How to install Python multiple versions under Ubuntu and Considerations _linux

Source: Internet
Author: User
Tags pack rehash git clone

The Ubuntu system was broken by carelessness today, because I unloaded the python3, and then ... Okay, no more nonsense, let's talk about how to manage multiple versions of Python under Ubuntu. I'm using a Python version management tool called Pyenv.

System environment: Ubuntu14.04lts, the system default Python version is 2.7, I would like to install a 3.4.3 version.

Before installing Python, we first need to install this management tool PYENV:

$ git clone git://github.com/yyuu/pyenv.git ~/.pyenv
$ Echo ' export pyenv_root= ' $HOME/.pyenv ' >> ~/.bashrc< c2/>$ echo ' Export path= ' $PYENV _root/bin: $PATH ' ' >> ~/.BASHRC
$ Echo ' eval $ (pyenv init-) "' >> ~/.BASHRC
$ exec $SHELL-L

We can also use the following command to view the version of Python that can be installed:

$ pyenv Install--list

If we are sure to install python3.4.3, we can then install Python, but before we install it, we have to install the dependent packages that Python needs, which must be installed, and the installation will fail:

$ sudo apt-get install libc6-dev gcc
$ sudo apt-get install-y make build-essential libssl-dev zlib1g-dev libbz2-dev L Ibreadline-dev Libsqlite3-dev wget Curl LLVM

After the above dependency pack is done, we can install Python:

$ pyenv Install 3.4.3-v

This command downloads the Python source code from the GitHub and extracts it into the/tmp directory, then executes the compilation in/tmp. If the dependent package is not installed, a compilation error occurs and the command needs to be rerun when the installation dependency pack is delayed.

After the installation is complete, you need to update the database with the following command:

$ pyenv Rehash

View the version of Python that is currently installed

$ pyenv Versions
* System (set by/home/seisman/.pyenv/version)
3.4.3

Where the asterisk represents the Python version that the current system is using is the system itself.

Set the global Python version

$ pyenv Global 3.4.3
$ pyenv Versions
System
* 3.4.3 (set by/home/seisman/.pyenv/version)

From the above, we can see that the current Python version has changed to 3.4.3. You can also use the pyenv local or pyenv shell to temporarily change the Python version.

Confirm Python version

$ python
python 3.4.3 (default, APR 1 2015, 19:10:43) 
[GCC 4.8.2] on Linux
Type ' help ', ' copyright ', ' credits ' or "license" for the more information.

Precautions:

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.3 and does not conflict with the system module;

After you install the module with the PIP, you may need to perform a pyenv rehash update database.

The above is a small set to introduce the Ubuntu under the installation of multiple versions of Python methods and precautions, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.