如何在Ubuntu 12.04上正确安装GTK +?

时间:2013-01-01 00:37:37

标签: python gtk ubuntu-12.04 openstreetmap

问题:我正在尝试在Ubuntu 12.04上安装GTK +,虽然它似乎已安装,但每次我尝试运行使用'import gtk'的python程序时,我都会得到错误:

Traceback (most recent call last):
  File "gps_slip_map.py", line 3, in 
    import gtk
ImportError: No module named gtk

可以找到gps_slip_map.py的python代码here

我到目前为止做了什么:我需要一些依赖项:osm-gps-map和gtk +。
为了下载osm-gps-map,我使用了来自here

的命令
sudo apt-get install libosmgpsmap-dev python-osmgpsmap


为了下载gtk +,我使用了来自here的命令,在'p0c4r1'后面#9:

sudo apt-get install gnome-core-devel build-essential libgtk2.0-dev libgtk2.0-doc devhelp

我已经安装了这两个,当我再次尝试时,我会收到此消息形式的确认:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
libosmgpsmap-dev is already the newest version.
python-osmgpsmap is already the newest version.
gnome-core-devel is already the newest version.
build-essential is already the newest version.
libgtk2.0-dev is already the newest version.
libgtk2.0-doc is already the newest version.
devhelp is already the newest version.
The following packages were automatically installed and are no longer required:
  language-pack-zh-hans yaml-cpp language-pack-kde-en libwxgtk2.6-0 language-pack-kde-zh-hans language-pack-kde-en-base libwxbase2.6-0 python-central language-pack-zh-hans-base
  language-pack-kde-zh-hans-base
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 165 not upgraded.

在这个项目上与我合作的朋友能够简单地安装Ubuntu 12.04 Precise并使用该命令安装osm-gps-map。这对他有用,软件运行时没有抛出ImportError。我做了同样的事情,但这对我不起作用。

结论:是否有人能够帮我弄清楚如何修复此ImportError?

更新1:似乎PYHTONPATH正确....命令'echo $ PYTHONPATH'显示:

  

PYTHONPATH:/usr/local/lib/python2.7/site-packages /

但是,当我使用命令'ls /usr/local/lib/python2.7/site-packages/'时,似乎在任何地方都没有列出GTK

dateutil                       ipython-0.14.dev-py2.7.egg-info  _mlt.so       numpy-1.6.2-py2.7.egg-info   pytz                 wx.pth
freenect-0.0.0-py2.7.egg-info  matplotlib                       mlt_wrap.o    pylab.py                     README               wxPython_common-2.8.12.1-py2.7.egg-info
freenect.so                    matplotlib-1.3.x-py2.7.egg-info  mpl_toolkits  pylab.pyc                    serial               wxversion.py
IPython                        mlt.py                           numpy         pyserial-2.6-py2.7.egg-info  wx-2.8-gtk2-unicode  wxversion.pyc

对我而言,这似乎是问题,但我不知道如何在这里手动添加正确的文件,以便我可以导入gtk。 有没有人知道如何做到这一点?

1 个答案:

答案 0 :(得分:2)

是的 - 听起来你还需要GTK +的Python绑定

例如:

  • apt-get install python-gtk python-glade2

您也可能出现配置不匹配的情况。请查看此链接中的建议: