Can a virtualenv inherit from another?

python, virtualenv

Solution

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:

activate `ENV2`:

`workon ENV2`

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.

Problem

I want to create one `virtualenv` using another as the starting point, is this possible? I have to use cases in mind: 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. 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`.

Original source

Related problems