2

I created an virtualenv with virtualenvwrapper:

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

Then I created a simple script named testme.py:

#!/usr/bin/env python
import pygtk

Result:

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

I tried this now many times and different ways but nothing worked...

Here is what I have done already:

  1. Try to install it with pip:
Command "python setup.py egg_info" failed with error code 1
  1. Install ruamel.venvgtk inside the virtualenv (https://pypi.python.org/pypi/ruamel.venvgtk/0.4.1)

  2. Link it directly (and add path):

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 it to the site-packages from 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/

I tried it now so many time. Could get it run 1 time, but could not reproduce it.

edit: I forgot to link pygtk itself.

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

oxidworks
  • 1,563
  • 1
  • 14
  • 37

2 Answers2

2

This is how it works now for me:

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/
oxidworks
  • 1,563
  • 1
  • 14
  • 37
0

You can use your system packages within virtualenv you need to create a new virtual environement using mkvirtualenv environment --system-site-packages

Chiheb Nexus
  • 9,104
  • 4
  • 30
  • 43