Isolate multiple Python virtualenv/virtualenvwrapper using a virtual environment

Source: Internet
Author: User
Tags virtual environment virtualenv

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.