Ubuntu 14.04 和 Python 2.7.6 的 virtualenv 中没有名为 pygtk 的模块

No module named pygtk in virtualenv with Ubuntu 14.04 and Python 2.7.6

我用 virtualenvwrapper 创建了一个 virtualenv:

mkvirtualenv test --no-site-packages
workon test
cdvirtualenv

然后我创建了一个名为 testme.py:

的简单脚本
#!/usr/bin/env python
import pygtk

结果:

$ python testme.py 
Traceback (most recent call last):
  File "testme.py", line 3, in <module>
    import pygtk
ImportError: No module named pygtk

我现在尝试了很多次,但没有任何效果...

这是我已经完成的:

  1. 尝试用pip安装:
Command "python setup.py egg_info" failed with error code 1
  1. 在 virtualenv (https://pypi.python.org/pypi/ruamel.venvgtk/0.4.1) 中安装 ruamel.venvgtk

  2. Link 直接(加上路径):

mkdir -p lib/python2.7/dist-packages/
ln -s /usr/lib/python2.7/dist-packages/gtk-2.0 lib/python2.7/dist-packages/
ln -s /usr/lib/python2.7/dist-packages/gobject lib/python2.7/dist-packages/
ln -s /usr/lib/python2.7/dist-packages/glib lib/python2.7/dist-packages/
ln -s /usr/lib/python2.7/dist-packages/cairo lib/python2.7/dist-packages/
add2virtualenv  lib/python2.7/dist-packages/
  1. Link 它从 sys.path:
  2. 到站点包
ln -s /usr/lib/python2.7/dist-packages/gtk-2.0 lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/gobject lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/glib lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/cairo lib/python2.7/site-packages/

我试了很多次了。可以得到它 运行 1 次,但无法重现它。

编辑: 我忘了 link pygtk 本身。

ln -s /usr/lib/python2.7/dist-packages/pygtk.py lib/python2.7/site-packages/

现在对我来说是这样的:

mkvirtualenv test --no-site-packages
workon test
cdvirtualenv


ln -s /usr/lib/python2.7/dist-packages/gtk-2.0 lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/gobject lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/glib lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/cairo lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/pygtk.py lib/python2.7/site-packages/

您可以在 virtualenv 中使用您的系统包 您需要使用 mkvirtualenv environment --system-site-packages

创建一个新的虚拟环境