How to install Python multiple versions under Ubuntu and considerations

Source: Internet
Author: User
Tags rehash
Today, I accidentally put the Ubuntu system out of the bad, because I unloaded the python3, and then ... Okay, no 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 want to install a 3.4.3 version here.

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

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

We can also view the version of Python that can be installed by using the following command:

$ pyenv Install--list

If we decide to install python3.4.3, then we can install Python, but before we install it, we have to install the dependencies required by Python, 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 Librea Dline-dev Libsqlite3-dev wget Curl LLVM

Once the above dependencies are done, we can install Python:

$ pyenv Install 3.4.3-v

The command downloads python's source code from GitHub, extracts it to the/tmp directory, and performs the compilation work in/tmp. If the dependent package is not installed, a compilation error will occur and the command needs to be re-executed at the time the installation dependency 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 indicates that the Python version currently in use by the system is the system's own.

Set the global Python version

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

From above, we can see that the current version of Python 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

$ Pythonpython 3.4.3 (default, APR 1, 19:10:43) [GCC 4.8.2] on Linuxtype ' help ', ' copyright ', ' credits ' or ' license ' F or more information.

Precautions:

Enter Python to use the new version of Python;

The system comes with a script that calls the old version of Python directly in a/usr/bin/python manner, and thus does not affect the system script;

Installing a third-party module using PIP will be installed under ~/.pyenv/versions/3.4.3 and will not conflict with the system module;

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

The above is a small series to introduce you to the Ubuntu installation of multiple versions of Python methods and notes, I hope that we have some help, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for your support for topic.alibabacloud.com!

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.