Compile and install Python 3 in Linux, and compile Python 3 in linux.

Source: Internet
Author: User

Compile and install Python 3 in Linux, and compile Python 3 in linux.
Compile and install Python 3 in Linux

Author: Xiu Yuxuan Chen @ cnblog

 

 

 

1 Preface

In Linux, the default system comes with python2.6, Which is depended on by many programs in the system. Therefore, we do not recommend that you delete it, if the latest Python3 is used, we know that there is no impact between the source package compilation and installation and the system default package, so we can install python3 and python2 to coexist.

First go to python official website to download python 3 source package, URL: https://www.python.org/

2 Installation

Add configuration and specify the installation directory

./Configure -- prefix =/usr/python

:

Compile

Make-j40

Install:

Sudo make install

The entire process is about 5-10 minutes. After the installation is successful, the installation directory is in/usr/python

In the system, the original python is in/usr/bin/python. You can see through ls-l that python is a soft link and linked to python2.6.

You can delete this file or create a soft link for python3, but change python to python3 during execution, or change the declaration in the python script header #! /Usr/bin/python3

We recommend that you rename the program and create a soft link. You do not need to change the header of the program:

# Modify the default system version

$ Sudo mv/usr/bin/python. bak

$ Sudo ln-s/usr/python/bin/python3/usr/bin/python

# Modify the local user version

$ Sudo mv/usr/bin/python/usr/bin/python2.6 # operate on the default python version

In this way, the python command will be directly executed, which is equivalent to calling python3. In fact, python3 is also a soft link, which is linked to python3.5.1. This multiple links do not actually affect, this is mainly for the convenience of version upgrade. You do not need to change the version number.

Try to use the python-V command:

(If python3.5 is displayed in sudo python-V but python2.7 is displayed in python-V, restart the server)

3. Question or question 3.1 What should I do if I still want to use python2.7?

Add the python2.7 path to the first line of the original python file:
#! /Usr/bin/python. bak

Or

#! /Usr/bin/python2.7 *

The above two statements are used to specify the python version.

3.2 The following is another issue: pip2.7 and pip3:

During installation, you may encounter the following problems:

Note: after the new version of python is installed, pip2 and pip3 are displayed. The two commands are different, as shown below:

1-The package location after installation is different

2-Pip2/3 is only applicable to their respective versions after installation.

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.