Virtualenv
Multiple python mixes in the system can lead $PYTHONPATH
to confusion, or the individual projects require different versions of the package, and so on. One simple solution is to isolate multiple Python with virtualenv, which is essentially isolating the paths in different python, but $PYTHONPATH
can also be derived to isolate multiple $PATH
.
Installing Virtualenv
# Ubuntu/Linux 64-bit$ sudo apt-get install python-pip python-dev python-virtualenv# Mac OS X$ sudo easy_install pip$ sudo pip install --upgrade virtualenv
Virtualenvwrapper
When there are many virtual environments, we may not be able to remember which virtual environments, it is more difficult to figure out which package is in each environment, so it is recommended to use Virtualenvwrapper to manage the virtual environment.
Configure Virtualenvwrapper
Install the virtualenv with PIP or install it with Apt-get before installing Virtualenvwrapper python-virtualenv
sudo pip install virtualenvwrapper
Add the following lines to ~/.BASHRC
export Virtualenvwrapper_python=/usr/bin/python2. 7 # This is to prevent the environment variable $path python that already has other environments and needs to be replaced with the Python path you need
Export workon_home=$HOME/.virtualenvs # Places to put all your virtual environments
source/usr/local/bin/virtualenvwrapper.sh
In the terminal inputsource ~/.bashrc
New Virtualenv
The instructions for creating a new virtual environment are replaced by the original virtualenv vpath
mkvirtualenv vname
, by default the path $WORKON_HOME
is placed below, and the original --system-site-packages
and --no-site-packages
other options are still available.
mkvirtualenv VirtalenvName
After the establishment of the default has entered the virtual environment (the command line will have a parenthesis + environment name hint), exit isdeactivate
Virtualenvwrapper Common directives
mkvirtualenv 创建环境workon 切换到环境deactivate 注销当前环境lsvirtualenv 列出所有环境rmvirtualenv 删除环境cpvirtualenv 复制环境cdsitepackages cd到当前环境的site-packages目录lssitepackages 列出当前环境中site-packages内容setvirtualenvproject 绑定现存的项目和环境wipeenv 清除环境内所有第三方包
Isolate multiple Python virtualenv/virtualenvwrapper using a virtual environment