virtualenvwrapper
Since virtualenv is not convenient for centralized management of virtual environments, it is recommended to use virtualenvwrapper directly. virtualenvwrapper provides a series of commands to facilitate working with virtual environments. It puts all your virtual environments in one place.
Install virtualenvwrapper (make sure virtualenv is installed)
pip install virtualenvwrapper
pip install virtualenvwrapper-win #Windows use this command
After the installation is complete, write the following in ~/.bashrc
VIRTUALENVWRAPPER_PYTHON=/usr/python-3.6.4/bin/python3
export WORKON_HOME=$HOME/envs
source /usr/python-3.6.4/bin/virtualenvwrapper.sh
The first line: the installation path of python
The second line: virtualenvwrapper stores the virtual environment directory
The third line: virtualenvwrapper will be installed in the bin directory of python, so the path is bin/virtualenvwrapper.sh in the python installation directory
source ~/.bashrc #Read in the configuration file, take effect immediately
Basic use of virtualenvwrapper
1. Create a virtual environment mkvirtualenv
mkvirtualenv venv
This will create a new virtual environment named venv in the directory specified by the WORKON_HOME variable.
If you want to specify the python version, you can specify the python interpreter with "--python"
mkvirtualenv --python=/usr/local/python3.5.3/bin/python venv
2. Basic commands
View the current virtual environment directory
[root@localhost ~]# workon py2 py3
Switch to virtual environment
[root@localhost ~]# workon py3 (py3) [root@localhost ~]#
Exit the virtual environment
(py3) [root@localhost ~]# deactivate [root@localhost ~]#
delete virtual environment
rmvirtualenv venv