Need to 'import gtk' on Ubuntu 20.04, what do I need?
Chris Green writes:
> I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu
> 20.04. [ ... ]
> The error I am getting is:-
[ ... ]
> ImportError: No module named gtk
> So what do I need to install on my Ubuntu 20.04 system to provide the
> gtk module?
Ubuntu doesn't provide python-gtk any more at all. Which makes a
number of programs rather difficult now ...
> Alternatively (but much harder work) what is the Python 3 equivalent
> of the the Python 2 pygtk and gtk modules.
... because there is no close equivalent. In Python 3, GTK is
accessed via something called GObject Introspection (module "gi")
which requires significant changes to code beyond the usual 2to3
You might be able to get the program working using pygtkcompat.
Try inserting these lines near the beginning of the program:
from gi import pygtkcompat
If that doesn't work, you might be able to get the old Python 2/GTK 2
packages working by installing these two files with dpkg -i.
No warranty of safety or efficacy implied.
Good luck! It was a nasty shock discovering that Ubuntu had removed
python-gtk, especially since they kept lots of other python2 packages
(I could have understood it if they'd removed python2 entirely).
I don't know what the reasoning was for removing python-gtk while