Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need to 'import gtk' on Ubuntu 20.04, what do I need?

263 views
Skip to first unread message

Chris Green

unread,
Jul 23, 2020, 4:48:15 PM7/23/20
to
I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu
20.04. I have some Oki printer/scanner driver software that is
written in Python 2 and, although python 2 is still installed on my
system it's no longer the default python and the Oki software no
longer runs.

The error I am getting is:-

chris@esprimo$ ./scantool.py
Traceback (most recent call last):
File "./scantool.py", line 52, in <module>
import gtk
ImportError: No module named gtk

So what do I need to install on my Ubuntu 20.04 system to provide the
gtk module?

Alternatively (but much harder work) what is the Python 3 equivalent
of the the Python 2 pygtk and gtk modules.


--
Chris Green
·

Akkana Peck

unread,
Jul 23, 2020, 9:39:36 PM7/23/20
to
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
Python migration.

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
pygtkcompat.enable()
pygtkcompat.enable_gtk(version='3.0')

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.

http://mirrors.kernel.org/ubuntu/pool/universe/p/pygtk/python-gtk2_2.24.0-6_amd64.deb
http://mirrors.kernel.org/ubuntu/pool/universe/g/gimp/gimp-python_2.10.8-2_amd64.deb

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
keeping python2.

...Akkana

Chris Green

unread,
Jul 24, 2020, 4:33:15 AM7/24/20
to
Akkana Peck <akk...@shallowsky.com> wrote:
> 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 ...
>
Not quite true. Originally this program failed with "ImportError: No
module named pygtk" so I fished around a bit (i.e. did some searches)
and installed python-gobject, python-gobject-2 and python-gi. Doing
this got me past the "No module named pygtk", but I get the "No module
named gtk" still. So Python GTK is sort of half available.


> > 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
> Python migration.
>
So is that what I'm getting by installing the things noted above.
I.e. 'import pygtk' is importing GObject things whereas 'import gtk'
is after the older stuff.

I'm a *fairly* competant Python programmer so, if I have to, I will
consider converting from using the gtk module to using the gi module,
are there any good tutorials which might help me down this road?


> 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
> pygtkcompat.enable()
> pygtkcompat.enable_gtk(version='3.0')
>
Ah, that sounds like it might be a reasonable path to try, I'll look
for documentation on pygtkcompat, it sounds as if that might be useful.


> 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.
>
> http://mirrors.kernel.org/ubuntu/pool/universe/p/pygtk/python-gtk2_2.24.0-6_amd64.deb
> http://mirrors.kernel.org/ubuntu/pool/universe/g/gimp/gimp-python_2.10.8-2_amd64.deb
>
Yes, I found one thread on stackoverflow which went down this sort of
route but it's not going to be a long term solution I suspect. I
think modernising and maintaining my own version of the code is going
to work better long term.


> 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
> keeping python2.
>
Yes, from my searches it seems to have bitten quite a few people.

Thanks for all the help.

--
Chris Green
·
0 new messages