Pyenv managing multiple versions of the Python environment

Source: Internet
Author: User
Tags virtualenv
This article mainly introduces the detailed use of pyenv to manage multiple versions of the Python environment, small series feel very good, and now share to everyone, but also for everyone to do a reference. Let's take a look at it with a little knitting.

As more and more projects are being developed at the same time, there is a need to constantly switch between different versions of the Python environment, so I think of pyenv. Previously used virtualenv can only manage versions of third-party libraries under the same Python version, but for cases that require switching between multiple versions, only pyenv is used.

Installation

Run the following command to download the installation automatically


$ curl-l Https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | Bash

After the installation is complete, you need to modify the ~/.BASHRC file to add the pyenv to the PATH. Here is the following line to add to the ~/.BASHRC file.


Export path= "/home/kongxx/.pyenv/bin: $PATH" eval "$ (pyenv init-)" eval "$ (pyenv virtualenv-init-)"

And then source a bit of environment


$. ~/.BASHRC

Managing Python versions with pyenv

First look at the version of Python that is already installed and in use on the current system.


$ pyenv versions* System (set By/home/kongxx/.pyenv/version)

Where system indicates that the package is installed. * Represents a Python environment that is currently in use.

View the version of Python that is currently available for installation.


$ pyenv install-lavailable versions:2.1.3 2.2.3 2.3.7 2.4 2.4.1 ...

Install the specified version of Python


$ pyenv Install 2.7.10Downloading python-2.7.10.tar.xz...-> https://www.python.org/ftp/python/2.7.10/ python-2.7.10.tar.xzinstalling python-2.7.10...patching file./lib/site.pyinstalled Python-2.7.10 to/home/kongxx/. pyenv/versions/2.7.10$ pyenv Install 3.2.1 ...

After installation, view the Python version that is now installed.


$ pyenv versions* System (set by/home/kongxx/.pyenv/version) 2.7.10 3.2.1

Using a version-developed Python


$ pyenv Global 3.2.1$ Python-vpython 3.2.1

View the Python version that is currently in use after use.


$ pyenv version3.2.1 (set by/home/kongxx/.pyenv/version) $ pyenv Versions System 2.7.10* 3.2.1 (set by/home/kongxx/.pyenv /version)

Manage virtualenv with pyenv

Create a VIRTUALENV environment

Here you use Python 3.2. To create a virtualenv environment


$ pyenv virtualenv 3.2.1 myenv$ pyenv Versions System 2.7.10* 3.2.1 (set by/home/kongxx/.pyenv/version) 3.2.1/envs/myenv Myenv

Activate the virtualenv you currently need to use


$ pyenv Activate myenv$ pyenv versions System 2.7.10 3.2.1 3.2.1/envs/myenv* myenv (set by pyenv_version environment Varia ble

Remove the virtualenv you currently need to use


$ pyenv Deactivate

Delete the virtualenv you currently need to use


$ pyenv Virtualenv-delete myenv
Related Article

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.