[kwlug-disc] Python 3.10 and GTK 3 Python Programs.

John Driezen jdriezen at sympatico.ca
Tue Nov 2 17:22:48 EDT 2021


I decided to install Python 3.10 on my Linux Mint 20.1 system in order 
to be able to use the match statement in place of if-elif-endif.  I 
successfully installed Python 3.10.  However, when attempting to run my 
python programs written with GTK 3, I get the following error message.

Traceback (most recent call last):
   File "/home/john/PythonProjects/DisplayPNGImage.py", line 1, in <module>
     import gi
   File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in 
<module>
     from . import _gi
ImportError: cannot import name '_gi' from partially initialized module 
'gi' (most likely due to a circular import) 
(/usr/lib/python3/dist-packages/gi/__init__.py)

The source code for DisplayPNGImage.py follows:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import Gio
from gi.repository import Gdk

class Image(Gtk.Window):
     def __init__(self):
         Gtk.Window.__init__(self)
         self.set_title("Image")
         self.connect("destroy", Gtk.main_quit)

         eventbox = Gtk.EventBox()r
         eventbox.connect("button-press-event", self.on_event_press)
         self.add(eventbox)

         image = Gtk.Image()
image.set_from_file("/home/john/PythonProjects/Scrap_Icon.png")
#image.set_from_file("/home/john/PythonProjects/Scrap_Metal_Icon.png")
         eventbox.add(image)

     def on_event_press(self, widget, event):
         print('click', widget, event.button, event.time)

window = Image()
window.show_all()

Gtk.main()

If the gi library can not be imported, do I need to wait for an update 
to the gi library/python bindings to use Python3.10?  Or is another 
solution available?

John Driezen

jdriezen at sympatico.ca





More information about the kwlug-disc mailing list