Pyenv method for Python multi-version coexistence management tools

Source: Internet
Author: User
Tags rehash
This article shares the Python multi-version coexistence management tool pyenv method.

Table of Contents

[TOC]

This is often the case:

Python 2.6 is provided in the system. you need some features in Python 2.7;

Python is 2.x, and Python 3.xis required;

In this case, you need to install multiple Python in the system, but it does not affect the Python that comes with the system. that is, you need to implement coexistence of multiple versions of Python. Pyenv is such a Python version manager.

1. install pyenv

$ git clone git://github.com/yyuu/pyenv.git ~/.pyenv$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc$ exec $SHELL -l

2. install Python

View the installable version

$ pyenv install --list

This command will list the Python versions that can be installed with pyenv. only a few are listed:

2.7.8 # latest version of Python 2
3.4.1 # latest version of Python 3
Anaconda-2.0.1 # support for Python 2.6 and 2.7
Anaconda3-2.0.1 # support for Python 3.3 and 3.4
Such as x. x only has the Python official version, and other shapes such as xxxxx-x.x.x, which have both names and versions, belong to the "derivative" or release version.

2.1 install Python dependency packages

When installing Python, you must first install other software packages on which Python depends. The following are known libraries that need to be installed in advance.

Under CentOS/RHEL/Fedora:

sudo yum install readline readline-devel readline-staticsudo yum install openssl openssl-devel openssl-staticsudo yum install sqlite-develsudo yum install bzip2-devel bzip2-libs

2.2 install the specified version

Run the following command to install python 3.4.1:

$ pyenv install 3.4.1 -v

This command will download the python source code from github, decompress it to the/tmp directory, and then execute the compilation in/tmp. If the dependency package is not installed, a compilation error occurs. you need to re-execute the command after installing the dependency package.

For scientific research environments, it is recommended to install the Anaconda release for scientific computing, pyenv install anaconda-2.1.0 installation 2. x, pyenv install anaconda3-2.1.0 installation 3. x;

Anacoda is very large, and it will be slow to download with pyenv. you can download it on the Anaconda official website and put the downloaded file in ~ /. Pyenv/cache Directory, pyenv will not be downloaded again.

2.3 update database

After the installation is complete, update the database:

$ pyenv rehash

View the python version currently installed

$ pyenv versions* system (set by /home/seisman/.pyenv/version)3.4.1

The asterisk indicates that python is currently in use.

2.4 set the global python version

$ pyenv global 3.4.1$ pyenv versionssystem* 3.4.1 (set by /home/seisman/.pyenv/version)

The asterisk indicates that python is currently in use.

2.4 set the global python version

$ pyenv global 3.4.1$ pyenv versionssystem* 3.4.1 (set by /home/seisman/.pyenv/version)

The global python version has changed to 3.4.1. You can also use pyenv local or pyenv shell to temporarily change the python version.

2.5 confirm python version

$ pythonPython 3.4.1 (default, Sep 10 2014, 17:10:18)[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linuxType "help", "copyright", "credits" or "license" for more information.>>>

3.0 use python

Enter python to use the new version of python;
The scripts provided by the system directly call the old python versions in the/usr/bin/python mode, so they do not affect the system scripts;
When you use pip to install a third-party module, it will be installed ~ /. Pyenv/versions/3.4.1 does not conflict with the system module.
After installing the module using pip, you may need to execute pyenv rehash to update the database;

The above section describes the pyenv method of the Python multi-version coexistence management tool. For more information, see other related articles in the first PHP community!

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.