CentOS7 upgrade Python3

CentOS7 installation Python3.x

CentOS (Community Enterprise Operating System, Chinese meant Community Enterprise Operating System) is one of the Linux distributions, it comes from the source code for Red Hat Enterprise Linux release in accordance with the provisions of the open-source compiled with.

CentOS 7 in the default installation of Python, but the 2.x version, due in 2020 python2.x will stop updating, so you need to upgrade to version 3.x. But because python2.x system integration, and many commands are to be based on python2.x, such as: yum. Therefore, when you update Python, it recommends new and old versions coexist.

Look at the current python version

[root@centos home]# python -V
Python 2.7.5

  
  
  • 1
  • 2

Download the new installation package and install python

Download python https://www.python.org/downloads/
select the version they need, I chose the latest version pyhton3.7.2, in turn execute the following command

[root@centos home]# yum install gcc gcc-c++ -y
[root@centos home]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
[root@centos home]# tar xvf Python-3.7.2.tar.xz 
[root@centos home]# cd Python-3.7.2/
[root@centos Python-3.7.2]# ./configure
[root@centos Python-3.7.2]# make
[root@centos Python-3.7.2]# make install

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Verify whether the installation was successful

Look at whether the installation was successful python3

[root@centos home]# python3-V
Python 3.7.2

  
  
  • 1
  • 2

Look again python2 is still there

[root@centos home]# python-V
Python 2.7.5

  
  
  • 1
  • 2

Set the default version python3

First check the python path
Here Insert Picture Description
in / usr / bin Now, look at the links
Here Insert Picture Description

python link is python2, so the direct implementation of python is equivalent to the implementation of Python2

The original python soft link Rename:

[root@centos home]# mv /usr/bin/python /usr/bin/python.bak

  
  
  • 1

The python link to python3:

[root@centos home]# ln -s /usr/local/bin/python3 /usr/bin/python

  
  
  • 1

Yum modify part of the file

After the upgrade to python 3.x, yum not working, yum need to edit the configuration file, use vim Open the following two files:
/ usr / bin / yum (vi / usr / bin / yum)
/ SR / libexec / urlgrabber Down--ext (VI / SR / libexec / urlgrabber-EXT-Down)
press i after modified as below

# /usr/bin/python 

  
  
  • 1

change into

# /usr/bin/python2.7

  
  
  • 1

Press esc, enter: wq to save and exit

Original articles published 0 · won praise 27 · views 80000 +

Guess you like

Origin blog.csdn.net/yimenglin/article/details/104746637