How to build a virtual environment using python

Source: Internet
Author: User
Tags virtualenv
I believe that every python knows how to develop different python projects. sometimes, the python version is different and the software package version is different. The best solution to this problem is to build an independent python environment for different projects. Let's take a look. Preface

I believe it is normal for python developers to have different python versions on the machine, because some development projects use 2.6 or 2.7, and some use 3.0 + versions, we need to use our virtual environment to manage these different versions, keep each environment clean and independent, and facilitate switching between different versions, so today, let's take a look at the use of python virtual environment setup tool pyenv.

1. Installation

git clone https://github.com/yyuu/pyenv.git ~/.pyenvecho ‘export PYENV_ROOT=”$HOME/.pyenv”‘ >> ~/.bash_profileecho ‘export PATH=”$PYENV_ROOT/bin:$PATH”‘ >> ~/.bash_profileecho ‘eval “$(pyenv init -)”‘ >> ~/.bash_profileexec $SHELLsource ~/.bash_profile

Log out and then log on.

2. common commands

Pyenv install-list # list installed python versions

Pyenv install-v 3.3.5 # install 3.3.5

Pyenv uninstall 3.3.5 # uninstall

Pyenv version # view the current version

Pyenv global 3.3.5 # switch to version 3.35

3. install pyenv-virtualenv

git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv  echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profilesource ~/.bash_profile

4. create a virtual environment

pyenv virtualenv 2.7.10 env2710

5. activate the virtual environment

pyenv activate env2710

Then you can install the required software in this environment.

6. exit the virtual environment

pyenv deactivate

For more information about how to build a virtual environment using python, refer to PHP!

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.