How to install PyGObject with a specific version of GLib?

64 Views Asked by At

For one of my python projects, I need GLib 2.76.6. Unfortunately, PyGObject has version 2.71.3. So I need a way to build PyGObject with GLib 2.76.6.

I tried to build from that source : https://pygobject.readthedocs.io/en/latest/contact.html But I got this error after the installation :

Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/nvidia/deepstream/deepstream-6.4/pygobject-3.44.2/gi/__init__.py", line 40, in <module>
    from . import _gi
ImportError: cannot import name '_gi' from partially initialized module 'gi' (most likely due to a circular import)
1

There are 1 best solutions below

0
Dan Yeaw On

Current version of PyGObject (3.46.0+) have the following system dependencies:

  • glib: >= 2.64.0

  • gobject-introspection: >= 1.64.0

  • libffi: >= 3.0

These version support LTS or newer versions of Linux, like Ubuntu 20.04 or Debian Bullseye.

To build PyGObject from source, you can follow the Getting Started Guide for your distribution with the Installing from PyPI with pip section. However, PyGObject isn't really built against a specific version of GLib since it doesn't link to GLib's libraries. Instead, it is using introspection. For this to work, GLib is scanned at compile time and metadata files are generated. Then language bindings can read this metadata and automatically provide bindings to call into the C library.