Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

ImportError: When using gi.repository .....

Tue Apr 27, 2021 5:42 am

A question for coders on Linux.
I'm busy rewriting Indexprint for Gimp. As we know python v2.7 and GTK 2 are deprecated and you have to install phyton 2 separately. So I have installed python 2 and GTK+3. According the instructons found here: https://python-gtk-3-tutorial.readthedo ... stall.html. Changed the Indexprint GUI from GTK 2 into GTK+3 with Glade but then the problems begin. I'm using the gi module and found an error. Trying to import gi module in the Python console of Gimp gives me the following:

------------------------------------
GIMP 2.10.24 Python Console
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0]
>>> import gi
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 39, in <module>
raise ImportError(_static_binding_error)
ImportError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183
>>>
-------------------------------

But using Python 2.7 in terminal (so not in Gimp) I'm able to import gi without any error.

I have read the the bugzilla, I looked at the __init__.py but I'm still puzzled I donot see a solution.
What should I change?? Any help should be appreciated.

Some system information:
Using LinuX 20.04 (Xubuntu) with GTK2, GTK+3, Python 2.7 and 3.8 installed.

Re: ImportError: When using gi.repository .....

Fri Apr 30, 2021 12:12 pm

moroquendo wrote:A question for coders on Linux.
I'm busy rewriting Indexprint for Gimp. As we know python v2.7 and GTK 2 are deprecated and you have to install phyton 2 separately. So I have installed python 2 and GTK+3. According the instructons found here: https://python-gtk-3-tutorial.readthedo ... stall.html. Changed the Indexprint GUI from GTK 2 into GTK+3 with Glade but then the problems begin. I'm using the gi module and found an error. Trying to import gi module in the Python console of Gimp gives me the following:

------------------------------------
GIMP 2.10.24 Python Console
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0]
>>> import gi
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 39, in <module>
raise ImportError(_static_binding_error)
ImportError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183
>>>
-------------------------------

But using Python 2.7 in terminal (so not in Gimp) I'm able to import gi without any error.

I have read the the bugzilla, I looked at the __init__.py but I'm still puzzled I donot see a solution.
What should I change?? Any help should be appreciated.

Some system information:
Using LinuX 20.04 (Xubuntu) with GTK2, GTK+3, Python 2.7 and 3.8 installed.


It's possibly a clash between GTK2 (as used by Gimp 2.x) and GTK3 (as used by your Python code).

Re: ImportError: When using gi.repository .....

Fri Apr 30, 2021 2:20 pm

Thank you Ofnuts I was already thinking about that. I will give it a try in a vm with Gimp + python 2.7 + GTK3

Re: ImportError: When using gi.repository .....

Fri Apr 30, 2021 2:26 pm

moroquendo wrote:Thank you Ofnuts I was already thinking about that. I will give it a try in a vm with Gimp + python 2.7 + GTK3


IMHO it's not a problem that you can solve with a VM. It is likely that the Python support in Gimp 2.x includes bits of GTK2 (for instance, to generate the automatic dialogs) and that this clashes with GTK3. You would have to stay with GTK2...

Re: ImportError: When using gi.repository .....

Fri Apr 30, 2021 2:41 pm

ofnuts wrote:
moroquendo wrote:Thank you Ofnuts I was already thinking about that. I will give it a try in a vm with Gimp + python 2.7 + GTK3


IMHO it's not a problem that you can solve with a VM. It is likely that the Python support in Gimp 2.x includes bits of GTK2 (for instance, to generate the automatic dialogs) and that this clashes with GTK3. You would have to stay with GTK2...


I donot hope so. GTK2 is already problematic, Glade 2 is also deprecated.
Post a reply