Because there are differences between Python2 and 3, it may be necessary to switch back and forth between 2 and 3 in your daily work. In the same Python version, there may be projects that need to use django1.8, and other projects need to use django1.9, so if you can switch freely in the local environment, it is very convenient for developers. Remember when I first started learning, because of the Python version of the problem, to their Mac reload many times, now think, really is a runny nose a tear ah. First, let's talk about how python2 and 3 can coexist in their own local environment through PYENV.
To install PYENV, we will execute some installation commands from GitHub on the clone, respectively:
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
echo ‘export PYENV_ROOT="$HOME/.pyenv"‘ >> ~/.bash_profile
echo ‘export PATH="$PYENV_ROOT/bin:$PATH"‘ >> ~/.bash_profile
echo ‘eval "$(pyenv init -)"‘ >> ~/.bash_profile
After installation, you need to launch a re-login or source ~/.bash_profile
With Pyenv's install command, you can see which Python installations pyenv currently support
pyenv install --list
Install python2.7.13 and 3.6.0 separately
pyenv install -v 2.7.13
pyenv install -v 3.6.0
Once the installation is complete, install PYENV-VIRTUALENV for project isolation
To install Pyenv-virtual, use the following command:
git clone https://github.com/yyuu/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
echo ‘eval "$(pyenv virtualenv-init -)"‘ >> ~/.bash_profile
Again, after the installation is complete, you need to launch login or source ~/.bash_profile
Once the installation is complete, we can create multiple different environments for the same Python interpreter
pyenv virtualenv 2.7.13 firstproject
pyenv virtualenv 2.7.13 secondproject
Viewing the work environment using the VIRTUALENV subcommand
pyenv virtualenvs
Enter or exit the work environment by activate or deactivate command
pyenv activate firstproject
Virtualenv+pyenv managing Python working environment