Python virtual environment: Virtualenv

Source: Internet
Author: User
Tags virtualenv

Python virtual environment: Virtualenv

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 -- no-site-packages parameter to create a virtual environment.
Virtualenv -- no-site-packages [Virtual Environment name]

Start the Virtual Environment
Cd ENV
Source./bin/activate

Note that at this time, the command line will have one more (ENV), which is the virtual environment name. 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 ~ /. Add the following to the bashrc 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.

1. Create a directory to store the Virtual Environment
Mkdir $ HOME/. virtualenvs

2. In ~ /. Add row in bashrc: export WORKON_HOME = $ HOME/. virtualenvs

3. In ~ /. Add source/usr/local/bin/virtualenvwrapper. sh to bashrc.

4. Run: source ~ /. Bashrc

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

You may also like the following article about Python:

Python: Search for files that meet the conditions in a specified directory

Python2.7.7 source code analysis

Directly run Python code without the need for the operating system

Install Python3.4 on CentOS source code

Python core programming version 2. (Wesley J. Chun). [Chinese version of hd pdf]

Python development technology details. (Zhou Wei, Zong Jie). [hd PDF scan version + book guide video + code]

Obtain Linux information using a Python script

Build a desktop algorithm transaction research environment using Python in Ubuntu

A Brief History of Python Development

Python details: click here
Python: click here

This article permanently updates the link address:

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.