[Operation and maintenance] Linux upgrade Python2

[Operation and maintenance] Linux upgrade Python2

  • Operating system: centos7
  • Python version: version 2.7.5 before upgrade, 2.7.18 after upgrade
  • python3 version: 3.6.8 before upgrade, 3.8.8 after upgrade

1. View the current python version

[root@1 ~]# python -V
Python 2.7.5

2. yum install python

[root@s143 ~]# yum install -y python2
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package python-2.7.5-90.el7.x86_64 already installed and latest version
Nothing to do

python2 upgrade steps

0. Find the version that needs to be upgraded

Find the version that needs to be installed or upgraded on the python official website (including all versions of python and python3).

 Find the required Python version

​​​​​​Index of /ftp/python/

1. Download the new version of python

[root@s143 opt]# wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz

2. Unzip the software package


[root@s143 opt]# tar -zxvf Python-2.7.18.tgz

3. Precompiled software package


[root@s143 opt]# cd Python-2.7.18
[root@s143 Python-2.7.18]# ./configure --prefix=/usr

4. Compile the software package


[root@s143 Python-2.7.18]# make

running build_scripts
creating build/scripts-2.7
copying and adjusting /opt/Python-2.7.18/Tools/scripts/pydoc -> build/scripts-2.7
copying and adjusting /opt/Python-2.7.18/Tools/scripts/idle -> build/scripts-2.7
copying and adjusting /opt/Python-2.7.18/Tools/scripts/2to3 -> build/scripts-2.7
copying and adjusting /opt/Python-2.7.18/Lib/smtpd.py -> build/scripts-2.7
changing mode of build/scripts-2.7/pydoc from 644 to 755
changing mode of build/scripts-2.7/idle from 644 to 755
changing mode of build/scripts-2.7/2to3 from 644 to 755
changing mode of build/scripts-2.7/smtpd.py from 644 to 755
/usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py

5. Install the software package


[root@s143 Python-2.7.18]# make install

6. Check the upgraded version


[root@s143 Python-2.7.18]# python -V
Python 2.7.18
 

question

Upgrade to python2.7.18 yum report error No module named rpm

报错信息:There was a problem importing one of the Python modules required to run yum. The error leading to this problem was:
No module named rpm

  • Reason for the error: python2.7.18 is the latest version of python2, which has removed the support for yum, and centos8 uses the dnf package installation tool by default.
  • Solution: Copy a python2.7.5 from other centos7 servers to the server /usr/bin directory, and then rebuild the python soft link.

Or edit user/bin/yum directly to the following

 

Guess you like

Origin blog.csdn.net/G971005287W/article/details/131433007