The simple use of Python's virtualenv

Source: Internet
Author: User

What is virtualenv?

Virtualenv can create a standalone python development environment, such as the current global development environment is python3.6, now we have a project to use django1.3, another project needs to use django1.9, this time you can use Virtualenv created the respective Python development environment.


Advantages of virtualenv
    • Make different application development environments Independent

    • Environment upgrade does not affect other applications, nor does it affect the global Python development environment

    • It prevents package management clutter and version conflicts from appearing in the system


install and create a new virtual environment
CMD under input: If your Python installation path has been added to the environment variable C:\>PIP install virtualenv

Create a new virtual environment:

c:\>virtualenv testenvusing base prefix ' c:\\python36 ' New python executable in C:\testenv\Scripts\python.exe  // The default installation is in the current directory installing Setuptools, Pip, Wheel...done.

You can look at the current directory:


activating and shutting down the current virtual environment
C:\testenv\scripts>activate           //Activation (TESTENV) c:\testenv\scripts>        //Note the terminal has changed (TESTENV) C:\testenv\ Scripts>deactivate         //Close the current virtual environment c:\testenv\scripts>


lists which packages are installed in the current virtual environment
(testenv) C:\TESTENV\SCRIPTS>PIP3 Listpip (9.0.1) setuptools (37.0.0) wheel (0.30.0)

Now you can install the packages you need to use in the virtual environment you created.


Virtualenvwrapper

It's an expansion pack for virtualenv, remember the top? Virtualenv need us to activate the active virtual environment. So let's look at the advantages of virtualenvwrapper.

C:\>pip Install Virtualenvwrapper-win   //installation c:\>mkvirtualenv Testenv2  //Create Virtual Environment C:\Users\liubin\Envs is Not a directory, creatingusing base prefix ' c:\\python36 ' New python executable in C:\Users\liubin\Envs\testenv2\Scripts\ Python.exe   //virtualenvwrapper defaults to placing the virtual environment in a directory installing Setuptools, Pip, Wheel...done. ( TESTENV3) C:\users\liubin\envs\testenv2\scripts>workon  //See what Virtual environments are currently pass a name to activate one of the following Virtualenvs:==============================================================================testenv2testenv3 ( TESTENV3) C:\users\liubin\envs\testenv2\scripts>workon testenv2  //workon can also be used to switch virtual environments (TESTENV2) c:\Users\ Liubin\envs\testenv2\scripts>



The simple use of Python's virtualenv

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.