1

I'm on Fedora 41, with a virtualenv with Python 3.12.7 (matplotlib==3.9.2). The following code:

import matplotlib.pyplot as plt
plt.figure(figsize=(10, 7))

or just

import gi
gi.require_version("Gtk", "4.0")

produce the error "AttributeError: module 'gi' has no attribute 'require_version'". When I try to install PyGObject with pip, I get the following error:

$ pip install PyGObject
  ...
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [48 lines of output]

      ...
      Compiler for C supports arguments -fvisibility=hidden: YES
      Found pkg-config: YES (/usr/bin/pkg-config) 2.3.0
      Run-time dependency cairo found: YES 1.18.0
      Run-time dependency python found: NO (tried pkgconfig, pkgconfig and sysconfig)
      
      ../cairo/meson.build:51:15: ERROR: Python dependency not found

same error with pip install cairo

I tried MANY solutions given by some similar posts:

$ pkg-config --modversion gtk4
4.16.5
$ pip uninstall gi
WARNING: Skipping gi as it is not installed.
$ pip install PyGTK
Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [4 lines of output]
      ********************************************************************
      * Building PyGTK using distutils is only supported on windows. *
      * To build PyGTK in a supported way, read the INSTALL file.    *
      ********************************************************************
      [end of output]
$ sudo dnf install python3-gi
Updating and loading repositories:
Repositories loaded.
Failed to resolve the transaction:
No match for argument: python3-gi
$ sudo dnf install python3-gobject
Updating and loading repositories:
Repositories loaded.
The package 'python3-gobject-3.48.2-3.fc41.x86_64' is already installed.

same for python3-gobject-base and gobject-introspection.

2 Answers 2

2

I was able to fix the problem by running pip install --upgrade pygobject.

I found the solution in this GitHub issue, which received the following reply:

It seems that the error message is related to the version of the Gtk module. the 'gi' module is not the version required by the Stable Diffusion WebUI , the version of Gtk that is being used is not compatible with the version of Matplotlib that is installed.. You could try running this command in your terminal :

" pip install --upgrade pygobject "

This command will upgrade the 'pygobject' module, which contains the 'gi' module .

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer, but I trying with --upgrade give me the same result as the original post : ../cairo/meson.build:51:15: ERROR: Python dependency not found (see above).
So you can just try to install the necessary dependency: pip install pygobject
1

I had the same issue while trying to install pycairo and tried all the suggested fixes, but nothing fixed this issue.

I finally fixed it by installing the correct version of python-devel the package, in my case:

sudo dnf install python3.12-devel  # check your python version and install the exact version

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.