News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

no datas

Linux python version upgrade

posted on 2023-05-07 20:32     read(223)     comment(0)     like(12)     collect(1)


I. Introduction

When   upgrading glibc , according to the INSTALL upgrade instructions, python version 3.4 or above is required. So the python version needs to be upgraded. The default installed python version of centos7 is 2.7.5, python can only install version 2.7.5 through yum, and python3 can install version 3.6.8 through yum. If you need a higher version, you can only compile and install it through source code. This blog post introduces the source code installation method to upgrade python and python3 versions. The source code compilation and installation requires the operating system to have gcc installed. The environment description is as follows:

  • Operating system: centos7.6
  • 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

Two, python installation steps

1. View the current python version

[root@s143 ~]# 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

3. yum install python3

[root@s143 ~]# yum install -y python3
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed:
python3.x86_64 0:3.6.8-18.el7

Dependency Installed:
libtirpc.x86_64 0:0.2.4-0.16.el7 python3-libs.x86_64 0:3.6.8-18.el7 python3-pip.noarch 0:9.0.3-8.el7 python3-setuptools.noarch 0:39.2.0-10.el7

Complete!

Three, python2 upgrade steps

0. Find the version that needs to be upgraded

Python official website (including all versions of python and python3) to find the version that needs to be installed or upgraded.
insert image description here

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

Four, python3 upgrade steps

1. Download the installation package

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

2. Unzip the software package

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

3. Precompile

Note that there will be a prompt "If you want a release build with all stable optimizations active (PGO, etc), please run ./configure --enable-optimizations" after the compilation is complete, and if you add --enable-optimizations precompilation, subsequent compilation will The error "Could not import runpy module" is reported because the gcc version is too low, and the enable-optimizations parameter requires gcc version 8.1.0 or higher.

[root@s143 opt]# cd Python-3.8.8
[root@s143 Python-3.8.8]# ./configure

4. Compile

[root@s143 Python-3.8.8]# make

if test `uname -s` = Darwin; then
cp python-config.py python-config;
fi

5. Compile and install

[root@s143 Python-3.8.8]# make install

Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2

6. Version check after upgrade

[root@s143 Python-3.6.10]# python3 -V
Python 3.8.8

5. QA

1. Error zlib not available when installing python3.8.8

  • Error message: zipimport.ZipImportError: can't decompress data; zlib not available
  • Reason for error: zlib module is not installed
  • Solution: Install the zlib module
    [root@s143 bin]# yum install -y zlib*

2. After installing python, yum reports an error File “/usr/bin/yum”, line 30

  • Error message: File “/usr/bin/yum”, line 30
    insert image description here
  • Reason for the error: The python soft link points to the python3 version, while yum requires the python2 version.
  • Solution 1: Modify the python command soft link to python2
    [root@s143 bin]# sln python2 python
    [root@s143 bin]# python -V
    Python 2.7.5
  • Solution 2: Modify the /usr/bin/yum file and change python to python2
    insert image description here

3. After installing python, the yum installation reports an error File “/usr/libexec/urlgrabber-ext-down”, line 28

  • Error message: File “/usr/libexec/urlgrabber-ext-down”, line 28
  • Reason for error: yum download program depends on python2
  • Solution 1: Modify the python command soft link to python2
  • Solution 2: Modify the /usr/libexec/urlgrabber-ext-down file and change python to python2
    insert image description here

4. After upgrading to python2.7.18, the error No module named rpm is reported

  • 报错信息: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
    insert image description here
  • 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.
    insert image description here


Category of website: technical article > Blog

Author:Believesinkinto

link:http://www.pythonblackhole.com/blog/article/331/3e83bc9abac9c9286af3/

source:python black hole net

Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.

12 0
collect article
collected

Comment content: (supports up to 255 characters)