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

StackOverflow https://stackoverflow.com/questions/11815272

  •  24-06-2021
  •  | 
  •  

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.

有帮助吗?

解决方案

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.

其他提示

If you have already created your virtual environment, just remove the no-global-site-packages.txt file from it to make it see system packages.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top