Virtualenv+pyenv managing Python working environment

Source: Internet
Author: User
Tags virtualenv

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.