Modifying a virtualenv so that packages installed

2019-02-02 10:48发布

问题:

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?

回答1:

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:

$ toggleglobalsitepackages env1

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)