1

尽管我安装了 python 的 gtk 绑定,但以下代码失败。这是一台 debian 机器,我安装了名为 python-gtk2 的包

>>> import gtk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named gtk

我怎样才能解决这个问题?

Edit1:根据评论请求:Python 2.7.3rc2(默认,2012 年 5 月 22 日,01:05:47)

Edit2:根据评论请求:

>>> print sys.path
['', '/home/lorb', '/usr/lib/python2.7/dist-packages', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages/SpssClient200', '/usr/local/lib/python2.7/site-packages/spss200']
4

1 回答 1

0

如果您使用的不是 Ubuntu 20,请执行此操作:

sudo apt install python-gtk2 libcanberra-gtk-module libcanberra-gtk3-module

如果您使用的是 Ubuntu 20,请执行此操作:

wget http://archive.ubuntu.com/ubuntu/pool/universe/p/pygtk/python-gtk2_2.24.0-5.1ubuntu2_amd64.deb && sudo dpkg -i python-gtk2_2.24.0-5.1ubuntu2_amd64.deb && sudo apt install --fix-broken && sudo dpkg -i python-gtk2_2.24.0-5.1ubuntu2_amd64.deb
于 2020-02-16T10:20:42.137 回答