I'm writing a Python script that uses a "recent" functionality in the Gio library.
How can I check that on the users system the library is recent enough?
Gio._version
the answer is 2.0
gi.require_version('Gio', '2.78')
before the import I get the error Namespace Gio is already loaded with version 2.0
/usr/lib/x86_64-linux-gnu/pkgconfig/gio-2.0.pc
says 2.80
but I'm not sure that users will have a .PC
file to check.Any solution, besides checking that the required functions are in the module directory?
For GLib specifically part of its API is GLib.MAJOR_VERSION
, GLib.MINOR_VERSION
, and GLib.MICRO_VERSION
: https://docs.gtk.org/glib/version.html
There might be a pygobject function for this but I didn't see one.
As you found out most of the gi
methods relate to the API version, not library version. So like Gtk
3.0
vs 4.0
.
I'll also add for dynamic languages you would sometimes check at runtime what is available, hasattr(GLib, 'some_new_method_i_want')
, instead of checking for version numbers.