Skip to main content
 首页 » 编程设计

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

2024年10月17日9duanxz

我用 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. 直接链接(并添加路径):

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. 将其链接到 sys.path 中的站点包:
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 次,但无法重现。

编辑:我忘了链接 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/