Python's Virtual Run environment

Source: Internet
Author: User
Tags virtual environment virtualenv

Python Virtual Environment: virtualenv Blog Category:
    • Python
Pythonavoid conflicts between different versions of Python or Python versions of components during Python development,

It is necessary to configure Python's virtual environment, this blog is transferred from http://liuzhijun.iteye.com/blog/1872241

Virtualenv

Virtualenv is used to create a stand-alone Python environment where multiple python is independent from each other and can:
1. Install the new kit without permission
2. Different applications can use different versions of the kit
3. Package upgrade does not affect other applications

Installation
sudo apt-get install python-virtualenv
How to use

For example, create a **env** virtual environment

virtualenv ENV

By default, the virtual environment relies on site packages in the system environment, which means that the installed third-party package in the system will also be installed in the virtual environment, if you do not want to rely on the package, you can add parameters to --no-site-packages establish a virtual environment

virtualenv --no-site-packages [虚拟环境名称]
Start the virtual environment
cd ENVsource ./bin/activate

Note that at this point the command line one more (ENV) , env is the virtual environment name, then all the modules will only be installed in the directory.

Exiting a virtual environment
deactivate
Installing a Python suite in a virtual environment

The virtualenv comes with the PIP installation tool, so the kit that needs to be installed can be run directly:

pip install [套件名称]

If the virtual environment is not started and the PIP tool is installed, the package will be installed in the system environment, in order to avoid this, you can ~/.bashrc add the following file:

export PIP_REQUIRE_VIRTUALENV=true

or let the system automatically turn on the virtual environment when the PIP is executed:

export PIP_RESPECT_VIRTUALENV=true
Virtualenvwrapper

Virtaulenvwrapper is an expansion pack for virtualenv that makes it easier to manage virtual environments and can do:
1. Integrate all virtual environments into one directory
2. Manage (add, delete, copy) virtual environments
3. Switch the virtual environment
4 .....

Installation
sudo easy_install virtualenvwrapper  

At this time can not use Virtualenvwrapper, the default virtualenvwrapper installed under/usr/local/bin, in fact, you need to run the virtualenvwrapper.sh file before the line, do not worry, open this file to see, There are installation steps, we set the environment according to the operation.

  1. Create a directory to hold a virtual environment

    mkdir $HOME/.virtualenvs
  2. Add rows in ~/.BASHRC: export workon_home= $HOME/.virtualenvs

  3. Add rows in ~/.BASHRC: source/usr/local/bin/virtualenvwrapper.sh

  4. Run:source ~/.bashrc

At this point the Virtualenvwrapper is ready to use.

List Virtual Environments

workon

You can also use

lsvirtualenv

Create a new virtual environment

mkvirtualenv [虚拟环境名称]

Start/Switch Virtual environments

workon [虚拟环境名称]

Deleting a virtual environment

rmvirtualenv [虚拟环境名称]

Leave the virtual environment

deactivate

Reference:
http://www.virtualenv.org/en/latest/
Http://stackoverflow.com/questions/11372221/virtualenvwrapper-not-found
http://www.openfoundry.org/tw/tech-column/8516- Pythons-virtual-environment-and-multi-version-programming-tools-virtualenv-and-pythonbrew
Http://virtualenvwrapper.readthedocs.org/en/latest/index.html

Python's Virtual Run environment

Related Article

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.