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