代码之家  ›  专栏  ›  技术社区  ›  Pickels

Python:virtualenv-gtk-2.0

  •  7
  • Pickels  · 技术社区  · 14 年前

    $ virtualenv --no-site-packages --python=/usr/bin/python2.6 myvirtualenv
    $ cd myvirtualenv
    $ source bin/activate
    $ cd lib/python2.6/
    $ ln -s /usr/lib/pymodules/python2.6/gtk-2.0/ 
    

    Virtualenv on Ubuntu with no site-packages

    我为什么要用sudo,有没有办法防止?

    更新:
    忘了提一下开罗和皮格特的工作,但这不是我需要的。


    http://www.friendly-stranger.com/pictures/symlink.jpg

    5 回复  |  直到 7 年前
        1
  •  10
  •   kenm    14 年前

    sudo python 导入它很好,因为解释器没有使用您的虚拟环境。所以别那么做。

    您只链接了一个必需的项目。把你所链接的问题的答案中提到的其他问题也做一遍。

    更新

    把这些东西放到$VIRTUALENV/lib/python2.6中/ 站点包/

    看起来.pth文件不是从该目录读取的-只是从站点包读取的

        2
  •  6
  •   t00m    13 年前

    这对我很有用(Ubuntu 11.10):

    激活virtualenv目录后,请确保“dist packages”存在:

    mkdir -p lib/python2.7/dist-packages/
    

    对于GTK2:

    ln -s /usr/lib/python2.7/dist-packages/glib/ 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/gtk-2.0* lib/python2.7/dist-packages/
    ln -s /usr/lib/python2.7/dist-packages/pygtk.pth lib/python2.7/dist-packages/
    ln -s /usr/lib/python2.7/dist-packages/cairo lib/python2.7/dist-packages/
    

    ln -s /usr/lib/python2.7/dist-packages/gi lib/python2.7/dist-packages/
    
        3
  •  1
  •   salomonvh    11 年前

    记住添加链接到pygtk.py公司

    ln -s /usr/lib/python2.7/dist-packages/pygtk.py lib/python2.7/dist-packages/
    
        4
  •  0
  •   Community CDub    7 年前

    在基于Debian的Linux系统(Ubuntu,Mint)上,您只需安装 ruamel.venvgtk 我放在PyPI上的包裹。它将在安装过程中在virtualenv中创建相关链接(如果还没有)。

    更详细的解释见 this answer

        5
  •  0
  •   thet    6 年前

    如果不要求在虚拟环境中不使用Python系统包,我将安装 apt install python-gtk2 (Ubuntu)创建虚拟环境:

    virtualenv --system-site-packages .

    这样,在虚拟环境中安装pip不会污染系统环境,而是重用系统中的所有内容。尤其是皮格特。