Discussion:
Need to 'import gtk' on Ubuntu 20.04, what do I need?
(too old to reply)
Chris Green
2020-07-23 20:41:32 UTC
Permalink
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:-

***@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
2020-07-24 01:39:09 UTC
Permalink
Post by Chris Green
I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu
20.04. [ ... ]
The error I am getting is:-
[ ... ]
Post by Chris Green
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 ...
Post by Chris Green
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
2020-07-24 08:31:05 UTC
Permalink
Post by Chris Green
Post by Chris Green
I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu
20.04. [ ... ]
The error I am getting is:-
[ ... ]
Post by Chris Green
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.
Post by Chris Green
Post by Chris Green
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?
Post by Chris Green
You might be able to get the program working using pygtkcompat.
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.
Post by Chris Green
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.
Post by Chris Green
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
·
Liste guru
2020-07-25 17:40:56 UTC
Permalink
Il 24/07/2020 10:31, Chris Green ha scritto:


   ...
Post by Chris Green
I'm a *fairly* competant Python programmer so, if I have to, I
willconsider converting from using the gtk module to using the gi
module,are there any good tutorials which might help me down this road?
   If you look at the pygobject documentation there is a chapter (and a
script, similar to 2to3) to help the migration:
https://pygobject.readthedocs.io/en/latest/guide/porting.html
Chris Green
2020-07-27 13:35:45 UTC
Permalink
Post by Liste guru
   ...
Post by Chris Green
I'm a *fairly* competant Python programmer so, if I have to, I
willconsider converting from using the gtk module to using the gi
module,are there any good tutorials which might help me down this road?
   If you look at the pygobject documentation there is a chapter (and a
https://pygobject.readthedocs.io/en/latest/guide/porting.html
Thanks, it looks as if this is the way I will have to go.

I guess converting to Python 3 and pygobject (for 3) will be a 'good
thing' in the long run and it will mean I will become familiar enough
with the software to keep maintaining it easily (and even fix some
annoying quirks).
--
Chris Green
·
Michael Torrie
2020-07-25 19:08:23 UTC
Permalink
Post by Chris Green
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:-
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?
Someone has made a PPA with the python2 pygtk2 package:

https://launchpad.net/~nrbrtx/+archive/ubuntu/python2-stuff

sudo add-apt-repository ppa:nrbrtx/python2-stuff
sudo apt-get install python-gtk2

I can't vouch for the source, so use at your own risk.
Loading...