“ImportError:没有名为gtk的模块”,尽管它已安装

时间:2013-05-31 23:46:03

标签: python debian pygtk

虽然我安装了用于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']

1 个答案:

答案 0 :(得分: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