e-satis e-satis - 7 days ago 5
Python Question

How to force my virtualenv to see this compiled module installed at the system level?

I installed the package python-gconf on Ubuntu 12.04 and played with it: it's a python binding to the gnome configuration tool, and there is no pypi package for it.

As soon as I created a virtualenv (without

--no-site-packages
), any attempt to import
gconf
would lead to
ImportError
.

The
gconf
module works fine at the system level, but not in the virtual env. I investigated, and opening python-gconf.deb teached me that it's just a gconf.so binary.

Searching for it tells me it's been installed in /home/lib/python2.7/dist-packages/gtk-2.0/gconf.so

I did try to force Python hands:

sudo ln -s /usr/lib/python2.7/dist-packages/gtk-2.0/gconf.so ~/.virtualenvs/appetizer/lib/python2.7/site-packages/


But it only resulted in:

>>> import gconf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: could not import gobject (error was: 'No module named gobject')


So I'm guessing it's very dependant to GTK.

Answer

You should create your virtualenv using --system-site-packages option to make all system packages visible. Symlinking external packages into virtualenv's structure also works for most situations when you need only one external package.