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

时间:2016-11-21 12:05:10

标签: python virtualenv pygtk

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

    3. 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中的site-packages:
      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/
        

        我现在试了很多次。可以让它运行一次,但无法重现它。

        编辑:我忘了链接pygtk本身。

          

        ln -s /usr/lib/python2.7/dist-packages/pygtk.py   LIB / python2.7 /站点包/

2 个答案:

答案 0 :(得分:2)

这就是我现在的工作方式:

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/

答案 1 :(得分:0)

您可以使用virtualenv内的系统包,使用mkvirtualenv environment --system-site-packages

创建新的虚拟环境