Python virtual environment: virtualenv, pythonvirtualenv

Source: Internet
Author: User
Tags virtual environment virtualenv

Python virtual environment: virtualenv, pythonvirtualenv
Virtualenv

Virtualenv is used to create an independent Python environment. Multiple Python environments are independent of each other and do not affect each other. It can:
1. Install the new suite without permission
2. Different Application versions can be used.
3. Kit upgrade does not affect other applications

Install
sudo apt-get install python-virtualenv
Usage
Virtualenv [Virtual Environment name]

For example, create a ** ENV ** virtual environment.

virtualenv ENV

By default, the virtual environment depends on the site packages in the system environment, that is, the third-party packages installed in the system will also be installed in the virtual environment. If you do not want to rely on these packages, you can add the Parameter--no-site-packagesCreate a virtual environment

Virtualenv -- no-site-packages [Virtual Environment name]
Start the Virtual Environment
cd ENVsource ./bin/activate

Note that at this time, the command line will have one more(ENV), ENV is the name of the virtual environment. Then, all modules will only be installed in this directory.

Exit the Virtual Environment
deactivate
Install Python kit in a Virtual Environment

Virtualenv comes with the pip Installation tool, so you can directly run the installation kit:

Pip install [suite name]

If the virtual environment is not started and the pip tool is installed in the system, the kit will be installed in the system environment. To avoid this problem, you can~/.bashrcAdd the following to the file:

export PIP_REQUIRE_VIRTUALENV=true

Or enable the system to automatically enable the virtual environment when executing pip:

export PIP_RESPECT_VIRTUALENV=true
Virtualenvwrapper

Virtaulenvwrapper is the extension package of virtualenv, which is used to facilitate the management of virtual environments. It can do the following:
1. Integrate all virtual environments into one directory
2. Manage (add, delete, and copy) Virtual Environment
3. Switch the Virtual Environment
4 ....

Install
sudo easy_install virtualenvwrapper  

Virtualenvwrapper cannot be used yet. By default, virtualenvwrapper is installed under/usr/local/bin. In fact, you need to run virtualenvwrapper. sh file. Don't worry. Open this file and check it. There are installation steps in it. We can set the environment according to the operation.

Now virtualenvwrapper can be used.

List Virtual Environments

workon

You can also use

lsvirtualenv

Create a virtual environment

Mkvirtualenv [Virtual Environment name]

Start/switch Virtual Environment

Workon [Virtual Environment name]

Delete Virtual Environment

Rmvirtualenv [Virtual Environment name]

Leave the Virtual Environment

deactivate

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.