Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a virtualenv inherit from another?

I want to create one virtualenv using another as the starting point, is this possible?

I have to use cases in mind:

  1. Let's say I have a two virtualenv one for production and one for development. The development environment requires the same packages as the production environment, but it requires others I don't want in the production environment. I don't want to install the common packages twice.

  2. I want to experiment with a development version of a package, say matplotlib for example. The development version of the package has the same requirements as the stable version. So I create a virtualenv called matplotib_stable and install the requirements and the stable version. Then I create a second virtualenv called matplotlib_dev and use matplotlib_stable as a starting point (for the matplotlib requirements) but then I install the development version.

How do I install from a local cache with pip? seems to address the issue of downloading packages, but I don't think it deals with modifying sys.path.

like image 298
Yann Avatar asked May 10 '12 16:05

Yann


People also ask

Can virtualenv be copied?

virtualenv-clone will be installed inside newenv. Now while logged-in as newenv we can create a copy of any existing environment. For example creating the copy of ProjectAenv: (newenv): virtualenv-clone ProjectAenv ProjectBenv (newenv): deactivate # to come out from newenv.

Does virtualenv inherit packages?

If you build with virtualenv --system-site-packages ENV , your virtual environment will inherit packages from /usr/lib/python2. 7/site-packages (or wherever your global site-packages directory is).

Can I move a virtualenv folder to another computer?

1 Answer. Kindly be informed that yes, it is possible to move it on the same platform. You can simply use --relocatable on an existing environment. But it will get changed based on the new location in order to call python and pip, etc.


1 Answers

One solution is to use virtualenvwrapper's add2virtualenv command. This

Adds the specified directories to the Python path for the currently-active virtualenv.

So if I have two virtualenv, ENV1 and ENV2, and I want ENV2 to access the packages in ENV1, then I need to:

  1. activate ENV2:

    workon ENV2

  2. add ENV1's site-packages directory using add2virtualenv:

    add2virtualenv $WORKON_HOME/ENV1/lib/python2.6/site-packages

The above assumes $WORKON_HOME is the location of your virtualenv directories, and that you are using python2.6, so obviously adjust those accordingly.

While this provides access to the packages it does not adjust the shell path. In other words, scripts installed to the bin directory are not accessible using this method.

like image 157
Yann Avatar answered Oct 16 '22 02:10

Yann