12

tl;dr I cannot install pygtk on Focal Fossa (Ubuntu 20.04) anymore but need it for my self-written PyGTK-based Python application.

I wrote a Python2 application some years ago based on GTK using the pygtk package. This worked fine for years now, I could always use the available Python2 installations, even when Python3 was the more modern variant.

With Focal Fossa (Ubuntu 20.04) Python2 support has been dropped, so I thought, no problem, I can upgrade my application to Python3. After doing it, I tried to install pygtk for Python3 using sudo pip3 install pygtk but this failed:

$ sudo pip3 install pygtk
Collecting pygtk
  Using cached pygtk-2.24.0.tar.bz2 (2.4 MB)
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-nezwkvr_/pygtk/setup.py'"'"'; __file__='"'"'/tmp/pip-install-nezwkvr_/pygtk/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-nezwkvr_/pygtk/pip-egg-info
         cwd: /tmp/pip-install-nezwkvr_/pygtk/
    Complete output (4 lines):
    ********************************************************************
    * Building PyGTK using distutils is only supported on windows. *
    * To build PyGTK in a supported way, read the INSTALL file.    *
    ********************************************************************
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

(The mentioned pygtk-2.24.0.tar.bz2 file wasn't to be found anymore, so I could not even look at the INSTALL file as suggested.)

I also found no package for apt install ... that would have installed it.

Alright, I thought, back to Python2. But unfortunately I cannot install pygtk for Python2 as well. I can install a python2 package, but there is no pip command and/or module anymore for Python2. (So neither pip ... nor pip2 ... nor python2 -m pip work. Maybe I just didn't find the correct way to do it.)

So I also could not install the Python2 version.

Then I briefly tried looking up how to install a non-packaged version of pygtk but that quickly dove even deeper into more dependencies (jhinstall, etc.) which seemed like taking even more time, and I'm lacking the experience in solving all these.

So I guessed maybe there is an easier solution and maybe someone here knows how to easily solve this issue. If nothing here pops up I will have to invest the time and solve the dependencies the hard way.

2
  • 5
    Does this answer your question? Why can't I import "pygtk" with Python 3.2 from PyDev?. You likely have the python3-gi deb package installed already -- you don't need to install it through pip.
    – user535733
    May 4, 2020 at 16:53
  • Indeed this seems to be a solution! So pygtk is discontinued in favor of a different framework API. Unfortunately this seems to mean I will have to modify larger parts of my code. It's not as simple as a sed 's/import gtk/from gi.repository import Gtk as gtk/g'.
    – Alfe
    May 4, 2020 at 17:33

1 Answer 1

21

You can install python-gtk2 manually from 18.04 LTS repository:

cd ~/Downloads
wget http://archive.ubuntu.com/ubuntu/pool/universe/p/pygtk/python-gtk2_2.24.0-5.1ubuntu2_amd64.deb
sudo apt-get install ./python-gtk2_2.24.0-5.1ubuntu2_amd64.deb

and use it as usual :)

3
  • 4
    I will consider using it but I prefer using official packages from official sources.
    – Alfe
    May 4, 2020 at 21:02
  • 1
    I came here looking for a trick for "diffuse" and I see your PPA has it. Maybe I should just use meld, but diffuse is what I'm used to. Thanks!
    – aap
    May 24, 2020 at 2:36
  • nice work. It works also for Linux Mint 20 which is based on Ubuntu 20.04
    – furas
    Aug 11, 2020 at 0:13

Not the answer you're looking for? Browse other questions tagged .