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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14107063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 10:28:25  来源:igfitidea点击:

How do I properly install GTK+ on Ubuntu 12.04 Precise?

pythongtkubuntu-12.04openstreetmap

提问by John Zeller

The Issue:I am trying to install GTK+ on Ubuntu 12.04, and while it seems to have installed, each time I attempt to run a python program which uses 'import gtk', I get the error:

问题:我正在尝试在 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

The python code for gps_slip_map.py can be found here

gps_slip_map.py 的 python 代码可以在这里找到

What I've Done So Far:There are a few dependancies that I needed here: osm-gps-map and gtk+.
In order to download osm-gps-map I used the command, from here:

到目前为止我做了什么:我在这里需要一些依赖项:osm-gps-map 和 gtk+。
为了下载 osm-gps-map 我使用了命令,从这里

sudo apt-get install libosmgpsmap-dev python-osmgpsmap


In order to download gtk+ I used the command, from here, post #9 by 'p0c4r1':


为了下载 gtk+,我使用了命令,从这里,通过“p0c4r1”发布 #9:

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

I have installed both of these and when I attempt to again, I receive confirmation in the form of this message:

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

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.

A friend who is working with me on this project was able to simply install Ubuntu 12.04 Precise and use the command to install osm-gps-map. This worked for him and the software ran without throwing an ImportError. I did this same thing, and it is not working for me.

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

Conclusion: Is someone able to help me figure out how to fix this ImportError?

结论:有人能帮我弄清楚如何解决这个导入错误吗?

Update 1:It seems as though the PYHTONPATH is correct.... the command 'echo $PYTHONPATH' shows:

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

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

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

But, when I use the command 'ls /usr/local/lib/python2.7/site-packages/', it seems as though there is NO GTKlisted anywhere.

但是,当我使用命令 '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

To me it seems like this is the issue, but I have no idea how to go about manually adding the proper file here so that I can import gtk. Does anyone have any idea how to do this?

对我来说,这似乎是问题所在,但我不知道如何在此处手动添加正确的文件,以便我可以导入 gtk。有谁知道如何做到这一点?

回答by paulsm4

Yes - it sounds like you also need the Python binding for GTK+

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

For example:

例如:

  • apt-get install python-gtk python-glade2
  • apt-get install python-gtk python-glade2

It's also possible that you have a configuration mismatch. Look at the advice in this link:

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