Make virtualenv inherit specific packages from your global site-packages

TheMeaningfulEngineer picture TheMeaningfulEngineer · Aug 22, 2012 · Viewed 98.3k times · Source

I'm looking for a way to make a virtualenv which will contain just some libraries (which i chose) of the base python installation.

To be more concrete, I'm trying to import my matplotlib to virtualenv during the creation of virtualenv. It can't be installed efficiently with pip or easy_install since it misses some fortran compiler libs. The way i did it till now was to manually copy from

/usr/lib/python2.7/dist-packages/ to virtualenv_name/lib/python2.7/dist-packages/

however this prevents the manully imported links to be registerd by yolk (which prints all currently available libs in virtualenv).

So, is there a way to do a selective variant of the

virtualenv --system-site-packages

Answer

foobarbecue picture foobarbecue · Oct 19, 2013

Create the environment with virtualenv --system-site-packages . Then, activate the virtualenv and when you want things installed in the virtualenv rather than the system python, use pip install --ignore-installed or pip install -I . That way pip will install what you've requested locally even though a system-wide version exists. Your python interpreter will look first in the virtualenv's package directory, so those packages should shadow the global ones.