Simple use of virtualenv in python, pythonvirtualenv
What is virtualenv?
Virtualenv can create an independent Python development environment. For example, the current global development environment is python3.6. Now we need to use django1.3 for one project and django1.9 for another project, in this case, you can use virtualenv to create your own python development environment.
Advantages of virtualenv
Independent Application Development Environments
Environment upgrades do not affect other applications or global python development environments.
It can prevent package management confusion and version conflicts in the system.
Install and create a virtual environment
Run the following command in cmd: Make sure that your python installation path has been added to the environment variable C: \> pip install virtualenv
Create a virtual environment:
C: \> virtualenv testenvUsing base prefix 'C: \ python36 'New python executable in c: \ testenv \ Scripts \ python.exe // by default, Installing setuptools, pip, wheel... done.
You can check it in the current directory:
Activate and disable the current Virtual Environment
C: \ testenv \ Scripts> activate // activate (testenv) C: \ testenv \ Scripts> // note that the terminal has changed (testenv) C: \ testenv \ Scripts> deactivate // close the current virtual environment C: \ testenv \ Scripts>
List packages 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 required package in the virtual environment you created.
Virtualenvwrapper
It is an extension package of virtualenv. Do you still remember the above? Virtualenv requires us to activate the virtual environment. Let's take a look at the advantages of virtualenvwrapper.
C: \> pip install virtualenvwrapper-win // install c: \> mkvirtualenv testenv2 // create a 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 puts the virtual environment in a directory by default Installing setuptools, pip, and wheel... done. (testenv3) c: \ Users \ liubin \ Envs \ testenv2 \ Scripts> workon // view the current virtual environments 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 the virtual environment (testenv2) c: \ Users \ liubin \ Envs \ testenv2 \ Scripts>