Multi-Python version coexistence configuration implemented in Python

Source: Internet
Author: User
Tags install openssl openssl readline rehash centos git clone in python

One, Windows environment

First of all, of course, install the two different versions of Python you need, I installed 2.7 and 3.4, two version of the installation does not matter, but the following installation will become the default (since I was installed after the Python 3.4, it becomes the default Python).

Then go to the Python27 folder to rename the Python.exe Python2.exe, and then invoke 3.x,python2 to invoke 2.x from the command line via Python or py.

In addition to Pip's words directly using PIP2 or PIP3 on it.

Second, Linux (CentOS for example) environment

Install Pyenv
1.git clone git://github.com/yyuu/pyenv.git ~/.pyenv2.echo ' export pyenv_root= ' $HOME/.pyenv ' >> ~/.BASHRC
3.echo ' Export path= $PYENV _root/bin: $PATH ' >> ~/.BASHRC
4.echo ' eval ' $ (pyenv init-) "' >> ~/.BASHRC
5.exec $SHELL-L
Install Python

To view a version that can be installed

1.pyenv Install--list This command lists Python versions that can be installed with pyenv, listing only a few:

1.2.7.8 # python 2 latest version 2.3.4.1 # Python 3 Latest version
3.anaconda-2.0.1 # supports Python 2.6 and 2.7
4.anaconda3-2.0.1 # supports Python 3.3 and 3.4
One such as x.x.x is only version number of the official Python version, the other shape such as xxxxx-x.x.x, which has the name and version of the "derivative version" or release version.

Installing a Python dependency pack
When you install Python, you need to first install the other software packages that it relies on, and some of the known libraries that need to be preinstalled are as follows.

Under the Centos/rhel/fedora:

1.sudo Yum install readline readline-devel readline-static2.sudo yum install OpenSSL openssl-devel openssl-static
3.sudo Yum Install Sqlite-devel
4.sudo Yum Install Bzip2-devel bzip2-libs

Install the specified version

Use the following command to install Python 3.4.1:

1.pyenv install 3.4.1-v This command downloads the Python source code from GitHub and extracts it into the/tmp directory, and then executes the compilation work in/tmp. If the dependent package is not installed, a compilation error occurs and the command needs to be executed again after the dependency package is installed.

For the scientific research environment, it is recommended to install the Anaconda distribution specially designed for scientific calculation, pyenv install anaconda-2.1.0 Install the 2.x version, pyenv install anaconda3-2.1.0 Install 3.x version;

Anacoda is very large, with pyenv download will be slower, you can go to the Anaconda official website download, and will download the files in the ~/.pyenv/cache directory, then pyenv will not repeat the download.

Update Database

The database needs to be updated after the installation is complete:

1.pyenv Rehash view of the currently installed Python version
1.$ pyenv versions2.* System (set By/home/seisman/.pyenv/version)
3.3.4.1
The asterisk indicates that the system is currently in use with Python.

Set the global Python version
1.$ pyenv Global 3.4.12.$ pyenv versions
3.system
4.* 3.4.1 (set by/home/seisman/.pyenv/version)
The current global Python version has become 3.4.1. You can also use the pyenv local or pyenv shell to temporarily change the Python version.

Confirm Python version

1.$ Python2. Python 3.4.1 (Default, Sep 10 2014, 17:10:18)
3.[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on Linux
4.Type "Help", "copyright", "credits" or "license" for the more information.
5.>>>

Using Python

Enter Python to use the new version of Python;

The scripts that come with the system will invoke the old version of Python directly in a/usr/bin/python way, and thus will not have any impact on the system script;
Installing a Third-party module with PIP is installed under ~/.pyenv/versions/3.4.1 and does not conflict with the system module.
After you install the module using the PIP, you may need to perform a pyenv rehash update database;

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.