Python3.3 and above versions natively support virtual environments through the venv module, which can replace the virtualenv before Python.
The venv module provides the creation of a lightweight "virtual environment" and provides isolation support from the system Python. Each virtual environment has its own Python binary (different Python version creation environments are allowed), and can have its own independent set of Python packages. His biggest advantage is that each python project can use a separate environment without affecting the python system environment or the environment of other projects.
advantage
- Make different application development environments independent
- Environment upgrade does not affect other applications, nor does it affect the global python environment
- Prevent package management confusion and version conflicts in the system
windows create virtual environment
Installed python3 environment, my python version is python3.5
My example here is to create a py3 directory in the root directory of the c drive and
enter the py3 directory
Create a virtual environment
python -m evnv c:\py3\
After the command is executed, you will see the following files in the py3 directory
Activate the virtual environment
or operate under windows cmd:
enter Scripts, execute activate.bat, the following figure shows that the activation is successful
At this time, you can enter python3 in the virtual environment and install the packages we need without affecting the python3 package environment installed by our system. Here I installed the pymysql package in the virtual environment, and then pip in the virtual environment and the outside environment. list lists the packages, you can see that there is no pymysql package in our external package
We have configured such a virtual environment
Mac or linux to create a virtual environment
In fact, there is not much difference between the methods of the three platforms, here is demonstrated through the Mac system, the python environment is still python3.5
Still create a py3 directory, and then enter the py3 directory
localhost:py3 zhaofan$ pwd
/Users/zhaofan/py3
Create a virtual environment
python3 -m venv .
Activate the virtual environment
source bin/activate
As shown below:
Then the virtual environment is created
All efforts are worthy of expectation, and every dream should be irrigated!