Linux-Centos7 installed with python3 and coexist with python2, python3python2

Source: Internet
Author: User

Linux-Centos7 installed with python3 and coexist with python2, python3python2

1. Check whether Python has been installed.

CentOS 7.2 is installed with python2.7.5 by default because some commands use it, such as yum, which uses python2.7.5.

Run the python-V command to check whether Python is installed.

Run the which python command to check the location of the Python executable file.

It can be seen that the execution file is in the/usr/bin/directory, switch to this directory and execute the ll python * command to view

Python points to python2.7.

Because we need to install python 3, python must point to python 3. Currently, python 3 has not been installed. Back up

Mv python. bak

2. Start compilation and installation of python3

Install related packages first

Yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

The related packages cannot be ignored. I have not installed readline-devel before, so that the upper, lower, and lower keys on the keyboard cannot be used for python mode execution;

 

Download the installation package from the official website or directly execute the following command to download it.

Wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

Extract

Tar-xvJf Python-3.6.2.tar.xz

Switch

Cd Python-3.6.2

Compile and install

./Configure prefix =/usr/local/python3

Make & make install

After the installation is complete, python3 will appear in the/usr/local/directory.

Therefore, we can add soft links to the/usr/bin directory.

Ln-s/usr/local/python3/bin/python3/usr/bin/python

You can see that the soft link has been created.

If the test is successfully installed, run

Python-V: Check whether the output version is python3.

Run python2-V to view the version of python2.

Because the execution of yum requires Python 2, we need to modify the yum configuration and execute:

Vi/usr/bin/yum

Put #! /Usr/bin/python #! /Usr/bin/python2

 

Similarly, in the vi/usr/libexec/urlgrabber-ext-down file #! /Usr/bin/python should also be modified #! /Usr/bin/python2

 

In this way, python3 is installed, and python2 also exists.

Python-V version 3

Python2-V Version 2

 

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.