Python, gtk, virtualenv, import gi not working

A year or two ago I learned a bit of Python then rolled up my sleeves and attempted to write my own booking software. After a few restarts I settled with using gtk and it was all plain sailing. Then I got bored and stopped.

Now I’m back (with a fresh install of Leap 15.5) and trying to pick up where I left off, except I can’t get my old code to work. The code is fine… it’s VSCode and a crucial module, gi. Evey time I try to run it I get “ModuleNotFoundError: No module named 'gi”.

How do I install gi? (!!)

I originally used an virtual environment to try to stop something like this from happening but I must have used the environment incorrectly. Besides, I coded it with Python 3.6 and VSCode now only supports 3.7+.

I created a new environment with Python 3.11. Somewhere on my travels I read that it’s PyGObject that I need but I’ve tried installing that, and pgi and no joy. I found this page and followed the steps inside and outside the environment and no joy.
https://pygobject.readthedocs.io/en/latest/getting_started.html#opensuse-getting-started

I’ve just deleted the new environment I created and started fresh so in a new Python 3.11 virtual environment what do I have to do to get these two lines to work as they should?

import gi
gi.require_version('Gtk', '3.0')

Thank you!

This would be python311-gobject except it is not built for Leap 15.5.

Ahhh, OK thanks.

I have python3-gobject installed… is that only good for Python 3.6? I’ve tried running the code in Python 3.10 and it won’t work.

As far as I can see, there is only Python 3.6, 3.10 and 3.11 in the repository so it seems impossible to get import gi to work - 3.6 doesn’t work in VSCode and 3.10 and 3.11 stop me from using “import gi”.

Will I get on any better if I just ditch Leap and use Tumbleweed?