Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying a virtualenv so that packages installed in global site-packages are available [duplicate]

Possible Duplicate:
Revert the `--no-site-packages` option with virtualenv

I've created a virtual environment using the virtualenvwrapper documentation as follows:

$ pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
$ mkvirtualenv env1

It works fine for the most part, but I've run into a few Django issues that require me to install some global packages outside of my virtual environment. Once I've installed these packages, how to I update my virtual environment to pull in these new packages? Or do I need to recreate the environment from scratch?

like image 387
Richard Keller Avatar asked Sep 14 '12 23:09

Richard Keller


People also ask

Can Python virtual environment use global packages?

virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.

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 copy virtualenv?

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.

What is the difference between VENV and virtualenv?

These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.


1 Answers

This question is a partial duplicate of: Revert the `--no-site-packages` option with virtualenv

However since this question specifically mentions virtualenvwrapper, the simplest solution when using virtualenvwrapper is to simply use its toggleglobalsitepackages command. It takes no parameters and affects only the active environment.

$ workon env1
(env1)$ toggleglobalsitepackages
Enabled global site-packages
(env1)$ toggleglobalsitepackages
Disabled global site-packages

Alternatively you can reinstall the virtualenv, reconfiguring it to have access to global packages, while keeping the packages already installed there with the command:

$ mkvirtualenv --system-site-packages env1

(thanks to @Adaephon for the heads up regarding toggleglobalsitepackages)

like image 196
Pedro Romano Avatar answered Oct 26 '22 23:10

Pedro Romano