The core purpose of installing a python virtual environment is to replicate a python environment so that all packages downloaded for a new project will be stored in the python site-package in the virtual environment.
first install
1. sudo pip install virtualenv # Install virtual environment
2. sudo pip install virtualenvwrapper # Install the Virtual Environment Extension package
3. vim .bash_profile # Edit the .bash_profile file in your home directory, adding the following three lines
export WORKON_HOME='~/.virtualenvs'
export VIRTUALENVWRAPPER_PYTHON='/Library/Frameworks//Versions/3.8/bin/python3'
source /Library/Frameworks//Versions/3.8/bin/
The first sentence defines the location of the virtual working directory folder.
In the second sentence, you need to fill in the location of your local python3 installation, which python3 can be found here.
In the third sentence, you need to fill in the location of the previously installed virtual machine. You can source to update this file to make it effective.
4. Save and run this command source ~/.bash_profile
So far the installation has been completed, add down the new working directory (npy007 for the new virtual environment)
Create a new virtual environment: mkvirtualenv -p python3 npy007 #After creating a new virtual environment successfully, the current path will be preceded by npy007.
Enter the virtual environment work:workon npy007
To see how many virtual environments are on the machine: workon tab double-click
Exit the virtual environment: deactivate
Remove virtual environment:rmvirtualenc npy007
Install the package in a virtual environment: pip install XXX # without sudo in front of it
To see which python packages are installed in your virtual environment: pip list
This is the whole content of this article.