e-satis e-satis - 8 months ago 38
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

), any attempt to import
would lead to

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 Source

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.