Use of python------virtualenv&virtualenvwrapper

Source: Internet
Author: User

Virtualenv

Virtualenv: Creating a standalone Python virtual environment for a single project

Use of virtualenv:

1. Install virtualenv with the following command

$ sudo pip install virtualenv

2. Create a virtual environment:

    • To create a default virtual environment:
$ virtualenv env27

This command indicates the creation of a virtual environment named ENV27. Each virtual environment contains a separate Env27/bin/python and env27/bin/pip that env27 as your running environment when running them.

    • To create a virtual environment that specifies the version of the interpreter:
$ virtualenv-p python2.7 env2.7 #解释器为python2.7
-P python3.4 env3.4 #解释器为python3.4
    • Create a virtual environment that inherits from a third party

If Python already has third-party libraries installed and you want to use them in a new virtual environment, you can use the following command:

$ virtualenv--system-site-packages env27

Use the following command if you do not want to use:

$ virtualenv--no-site-packages env27

3. Start and exit the virtual environment

    • Start the virtual environment

To start the ENV27 virtual environment, simply run the following command:

$ source Env27/bin/activate

This command modifies the system path $path, env27/bin the path to the system path.

The source command represents a change to the current shell environment.

After the virtual environment is started, all new third-party packages for the PIP command will be installed in the current environment without affecting the system environment or other virtual environments. 、

    • Exiting a virtual environment

To exit the current virtual environment simply execute the following command:

$ deactivate

Virtualenvwrapper

Virtualenvwrapper is a tool based on virtualenv that manages the desired virtual environment.

Installation

As the following command:

$ sudo pip install Virtualenvwrapper

Virtualenvwrapper all virtual environments are managed by default in the ~/.virtualenvs directory, you can modify the environment variable workon_home to specify the storage directory for the virtual environment.

Use the following command to start Virtualenvwrapper:

$ source/usr/local/bin/virtualenvwrapper.sh

You can also add the command to a shell startup file such as ~/.BASHRC or ~/.profie so that you can use the commands provided by Virtualenvwrapper directly after you log in to the shell.

For virtualenvwrapper configuration:

The code is as follows:

if ' 0 '  ]; Then  export Virtualenv_use_distribute=1        #  <--all use Pip/distribute  Export workon_home= $HOME/.virtualenvs       #  <--Where all Virtualenvs 'll be stored  source/usr/local/bin/virtualenvwrapper.sh  export pip_virtualenv_base=$WORKON _home  Export pip_respect_virtualenv=Truefi

Add the above configuration to the end of ~/.BASHRC, and then run the following command one time:

SOURCE ~/.BASHRC

Usage

    • Create a virtual environment
$ mkvirtualenv env27
    • Create a virtual environment for the specified interpreter
$ virtualenvwrapper-p python3.4 env34

    • Start the virtual environment
$ Workon env27

    • Exiting a virtual environment
$ deactivate

    • Deleting a virtual environment

$ rmvirtualenv env27

Use of python------virtualenv&virtualenvwrapper

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.