Python creates a standalone virtual work environment method

Source: Internet
Author: User
Tags virtual environment virtualenv

Objective:

Python has a lot of components, sometimes the project depends on M components, and sometimes the project depends on N components, the time can easily lead to the system Python environment is bloated, thus has the virtualenv, virtualenvwrapper the existence value.

How to use:

Excerpted from--HTTP://WWW.JIANSHU.COM/P/3ABE52ADFA2B

Virtualenv is used to create a stand-alone Python environment where multiple python is independent from each other and can:

    1. Install a new suite without permissions

    2. Different versions of the suite can be used for different applications

    3. Package upgrades do not affect other apps.

Installation method

1, the shell under Operation:

install python-virtualenv

2. How to use

[虚拟环境名称-也是目录名称]

3. Start the Environment

cd ENVsource ./bin/activate

Env is the virtual environment name, and all of the modules will be installed in that directory.

By default, the virtual environment relies on site packages in the system environment, and if you do not want to rely on these package, you can add the parameter--no-site-packages to establish the virtual environment:

virtualenv --no-site-packages [虚拟环境名称]

4. Exit

deactivate

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 add the following in the ~/.BASHRC 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. Consolidate all virtual environments in one directory

    2. Manage (new, delete, copy) virtual environments

    3. Quickly switch virtual environments

    4. ...

Installation method

1. Operation

install virtualenvwrapper

2. Create a directory to store the virtual environment

mkdir ~/.virtualenvs

3. Add in. bashrc

export WORKON_HOME=~/.virtualenvssource /usr/local/bin/virtualenvwrapper.sh

4. Operation:source ~/.bashrc

At this point the Virtualenvwrapper is ready to use.

Command List

Workon: List of Virtual environments

Lsvirtualenv: Ibid.

MKVIRTUALENV: New Virtual environment

Workon [Virtual Environment name]: switching Virtual environments

RMVIRTUALENV: Deleting a virtual environment

Deactivate: Leaving the virtual environment

Python creates a standalone virtual work environment method

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.