A virtual environment is a virtualized, computer-independent Python environment. It can be thought of as a container in which to install modules and packages that we rely on for our projects. In the actual project development, we usually according to their own requirements to download all sorts of corresponding packages and modules, but perhaps each project USES the framework of library is not the same, or using a framework version is different, so when doing the different projects will be very inconvenient, we constantly according to need to uninstall and install the corresponding and module package virtual environment:

Us more convenient to manage through the virtual environment, related environment depend on the package, each project used in the above situation, we can create two virtual environment in the system, respectively, to manage our project a and project 2 used depends on the package, the project relies on a used environment installed in a virtual environment, project 2 used depend on the installed in project 2, Although the two projects use two versions of the same package, we can isolate them through virtual environments

Here is a brief introduction to the installation and configuration of python3 virtual environment.

1. Prerequisites for Installation and configuration in Windows: PIP install virtualenv PIP install virtualenvwrapper-win

Env or virtualenv are recommended. 3. Configure environment variables. Add environment variables to the system environment variables

Step 4: Open the CMD terminal and enter workon to check whether the configuration is successful. Step 2: Install the virtual environment and management tool pip3 install virtualenv pip3 install virtualenvwrapper

Establishing a soft connection

Ln -s/usr/local/python3 / bin/virtualenv/usr/bin/virtualenv step 2: configure virtualwrapper environment variables Create a virtual environment home directory mkdir ~ /. Virtualenv

Use vim to open the. Bashrc file vim ~/. Bashrc

Add the following information, save the Settings, and exit export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

The directory stored in the virtual environment

export WORKON_HOME=$HOME/.virtualenvs source /usr/local/python3/bin/virtualenvwrapper.sh

Run the source ~/. Bashrc command to make the configuration take effect

Step 3: Enter the workon command to check whether the installation is successful. If no error message is displayed, the installation and configuration is successful. Install virtual environment and management tools pip3 install virtualenv pip3 install virtualenvwrapper

Step 2: Configure the environment variables for VirtualWrapper to create the virtualenv directory mkdir ~/.virtualenv

Check which Python is the directory where python3 is located

Check which virtualenvwrapper.sh is located

Use vim to open the ~/. Bash_profile file vim ~/.bash_profile

Add the following information and save it. Exit the export VIRTUALENVWRAPPER_PYTHON= # command which python3

The directory stored in the virtual environment

Export WORKON_HOME=$HOME/. Virtualenvs source # Directory queried by running the which virtualenvwrapper.sh command

Run the source ~/.bash_profile command to make the configuration take effect

Step 3: Enter the workon command to check whether the configuration is successful. Run the following command to create a virtual environment: mkvirtualenv Delete the virtual environment rmvirtualenv Check all virtual environments. workon Enter the virtual environment. Deactivate install the related package in the virtual environment. Workon Virtual environment name. PIP install package name. Installation package Uninstalls packages in the virtual environment workon Virtual environment name PIP uninstall Package name


Remember to pay attention!