Focal Fossa (20.04)上没有可用的pygtk吗?

tl;dr 我无法在Focal Fossa(Ubuntu 20.04)上安装pygtk,但我需要它来运行我自己编写的基于PyGTK的Python应用程序。

几年前,我基于GTK编写了一个使用pygtk包的Python2应用程序。这些年来一直很好用,即使Python3是更现代的变体,我仍然可以使用可用的Python2安装。

在Focal Fossa(Ubuntu 20.04)中,不再支持Python2,所以我想,没问题,我可以将我的应用程序升级到Python3。在升级后,我尝试使用sudo pip3 install pygtk为Python3安装pygtk,但失败了:

$ 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.

提到的pygtk-2.24.0.tar.bz2文件已经找不到了,所以我甚至无法查看安装文件INSTALL中的内容。我也没有找到apt install ...的软件包来安装它。
好吧,我想回到Python2。但不幸的是我也不能为Python2安装pygtk。我可以安装一个python2软件包,但是对于Python2来说,没有pip命令和/或模块了。(所以pip...、pip2...或python2 -m pip都不起作用。也许我只是没找到正确的方法。) 所以我也无法安装Python2版本。
然后我简要尝试了一下如何安装非打包版本的pygtk,但很快就深入到更多的依赖关系(jhinstall等),这似乎需要更多的时间,而我在解决所有这些问题方面缺乏经验。
所以我猜可能有一个更简单的解决方案,也许这里有人知道如何轻松解决这个问题。如果这里没有任何解决方法,我将不得不花时间去解决这些依赖关系的困难方式。

5这个回答解决了你的问题吗?为什么我无法从PyDev导入Python 3.2中的"pygtk"?。你很可能已经安装了python3-gi deb软件包--你不需要通过pip来安装它。 - user535733
确实,这似乎是一个解决方案!所以pygtk已经停止使用,转而采用了一个不同的框架API。不幸的是,这似乎意味着我将不得不修改我的代码的大部分内容。这并不像简单的sed 's/import gtk/from gi.repository import Gtk as gtk/g'那样简单。 - Alfe
1个回答

你可以从18.04 LTS仓库手动安装python-gtk2
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

并且像往常一样使用它 :)


4我会考虑使用它,但我更倾向于使用官方来源的正式软件包。 - Alfe
1我来这里是为了寻找“diffuse”的技巧,看到你的PPA有它。也许我应该只使用meld,但是我习惯使用diffuse。谢谢! - aap
干得好。它也适用于基于Ubuntu 20.04的Linux Mint 20。 - furas