How to install Python3 on Centos7 (personal test and efficient)

How to install Python3 under Centos7

        Since centos7 originally installed Python2, and this Python2 cannot be deleted, because there are many system commands, such as yum, which are used.

[root@VM_105_217_centos Python-3.6.2]# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Enter the Python command and check that it is Python2.7.5 version

enter

which python

You can check the location, which is usually located in the /usr/bin/python directory.

The following describes how to install Python3

First install dependency packages

yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

Then download different versions of Python3 according to your needs. I downloaded Python3.6.2

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

If the speed is not fast enough, you can download it directly from the official website and use WinSCP and other software to transfer it to the specified location on the server. My storage directory is /usr/local/python3. Use the command:

mkdir /usr/local/python3 

Create an empty folder

Then unzip the compressed package, enter the directory, and install Python3

tar -xvJf  Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install

Finally create a soft link

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

Enter python3 test in the command line

In addition: After this method is installed, an error will be reported when using yum. It can be modified as follows

Modify the yum configuration file (vi /usr/bin/yum). Change #!/usr/bin/python in the header of the file to #!/usr/bin/python2.7.

Modify the /usr/libexec/urlgrabber-ext-down file and point python to python2.7 as well.

Because yum is written based on Python, and some syntaxes of Python3 and Python2 are different.

At this point, the python3 installation is complete.

This article is reproduced from: https://www.cnblogs.com/FZfangzheng/p/7588944.html

Guess you like

Origin blog.csdn.net/i_likechard/article/details/119994177