Fedora37 Python3 Gtk4 dependencies issue

Hi, I’ve tried other forum but without success.

It has been several days. I’ve been trying to play around a bit with python3 and gtk4 to build a little app. But I’ve been stuck with dependencies issues. I’ve tried with vs code, and I’m having a ModuleNotFoundError: No module named ‘gi’. Also several errors trying to install this gi dependecy.

I’ve tried other forums, but stilt now help.

Using pycharm I’m having the following errors:

Traceback (most recent call last):
File “/home/tj/PycharmProjects/pythonProject/main.py”, line 2, in
gi.require_version(‘Gtk’, ‘4.0’)
File “/home/tj/PycharmProjects/pythonProject/venv/lib/python3.10/site-packages/gi/init.py”, line 129, in require_version
raise ValueError(‘Namespace %s not available for version %s’ %
ValueError: Namespace Gtk not available for version 4.0

or version 3.0:

Failed to load module “canberra-gtk-module”
Failed to load module “pk-gtk-module”

But at least this time a gtk window appeared. Thats a huge improvement for the last days :smiley:

I’ve been having issues with lack of documentation, or the quality of the documentation, for the setup process for pyGtk4 (specially for a newbie).

ModuleNotFoundError: No module named ‘gi’.
Also several errors trying to install this gi dependency.

Without more details it’s hard to help there

ValueError: Namespace Gtk not available for version 4.0

So this suggests you don’t have gtk4 installed, and least from the perspective of pycharm. Are you using a flatpak version perhaps?

I think I am using a flatpack vestion yes.
How can I help providing more details?

sh-5.1$ /bin/python /home/tj/Documents/python.py
Traceback (most recent call last):
File “/home/tj/Documents/python.py”, line 2, in
import gi
ModuleNotFoundError: No module named ‘gi’

Regarding python3:

which python3–> /usr/bin/python3

which python3, echo $PATH
which: no python3, in (/home/tj/.local/bin:/home/tj/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin)
which: no sbin in (/home/tj/.local/bin:/home/tj/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr)

It’s weird not to have pygobject installed on Fedora, but it might happen.

Have you tried installing the python3-gobject package?

That’s because it depends on your distribution.

In general, GNOME strongly recommends using GNOME Builder and Flatpak to get a full development environment, regardless of Linux distribution on your OS.

You can start from the beginners tutorials on the GNOME developers documentation website.

1 Like

$ sudo dnf install python3-gobject

Last metadata expiration check: 0:26:33 ago on Thu 24 Nov 2022 11:26:08 AM WET.
Package python3-gobject-3.42.2-2.fc37.x86_64 is already installed.
Dependencies resolved.
Nothing to do.

Perhaps the wrong version?

I was trying to not jump directly on gnome builder because it brings a lot of code/files already on it. Seemed a bit overwhelming to get around it for a first approach. But eventually I will have to go there.

I’m just playing with a few widgets at this point (gtk3, because for some reason, even with warnings, it runs on pycharm).

(they are using flatpak’d pycharm)

For whatever reason, the fd.o SDK contains gtk3 but not gtk4. So the flatpak would have to be changed to expose libraries from the host system, or changed to use the GNOME runtime to get access to gtk4.

How can I do that? :exploding_head:

Look in the manifest file of your project (generally a json or yaml file named after your project’s URI in the root folder) where the SDK and Runtime are specified. In Gnome-builder, when you change those parameters, the right Flatpak Sdk & runtime are automatically installed.

Because it is interesting, could you tell us how you setup your development environment ?

Isn’t it possible possible ( and maybe easier ) to install, maintain and keep all your development environment in a python virtual environment ?
After that you can choose from Pycharm or any other (I think) IDE to use the virtual python environment of your choice.

( I’m not a flatpak friend )

When pycharm is running the script in it’s runtime, and that runtime doesn’t include gtk4, venvs won’t do much


You can try this.

  1. install gtk
    $ dnf install python3-gobject gtk4

  2. install python module
    $ pip3 install PyGObject pycairo

The document is here. I tried it on Ubuntu, though.

That will not help you at all in the case of a Flatpak, because a) you can’t install anything inside a Flatpak and b) the Flatpak won’t see what’s installed in your system.

You don’t, unless you check out the PyCharm manifest and you rebuild the Flatpak bundle yourself.

PyCharm is built on top of the freedesktop run time, which means it does not have access to GTK4.

If you want to write GTK4/libadwaita applications for GNOME, the strong recommendation is to use GNOME Builder instead of PyCharm. Or, if that’s not possible for you, then you’ll have to install PyCharm using your distribution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.