1. Install virtualenv
pip install virtualenv virtualenvwrapper
2. Configuration file
Modify ~/.bash_profile or other environment variable related files (such as .bashrc or .zshrc after ZSH), and add the following statement:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/workspace
source /usr/local/bin/virtualenvwrapper.sh
* Note that the address of /usr/local/bin/virtualenvwrapper.sh should be determined according to the actual situation and should be used
find / -name virtualenvwrapper.sh
to determine the location of the modified file. For example my location is:
/usr/local/python3.5.2/bin/virtualenvwrapper.sh
3. Make the configuration file take effect
source ~/.bash_profile
** I have a problem here, that is, the error /usr/bin/python has no xxx. I saw that because my virtual machine is coexisting with Python 2 and Python 3, so he reported an error like this, it must be somewhere using Python 2 , so I'm sure that the file virtualenvwrapper.sh uses Python 2, so I went to this file and found this line
VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
Obviously, such a code means to give Python's running address to this variable. So I changed it to
VIRTUALENVWRAPPER_PYTHON="$(command \which python3)"
Later, an error was reported. Because the source ~/.bash_profile command has been executed before, the variable VIRTUALENVWRAPPER_PYTHON has been generated, so I delete the environment variable with the unset command. Just execute source ~/.bash_profile again.
Another problem arises. When executing the command mkvirtualenv to create a virtual environment, an error command not found is reported. To find a solution on Stack Overflow, add the following to the .bashrc configuration file:
export PATH=/usr/local/python3.5.2/bin:$PATH
** Note that /usr/local/python3.5.2/bin is the python3 installation address.