posted on 2023-05-07 20:32 read(276) comment(0) like(12) collect(1)
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:
[root@s143 ~]# python -V
Python 2.7.5
[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
[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!
Python official website (including all versions of python and python3) to find the version that needs to be installed or upgraded.
[root@s143 opt]# wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
[root@s143 opt]# tar -zxvf Python-2.7.18.tgz
[root@s143 opt]# cd Python-2.7.18
[root@s143 Python-2.7.18]# ./configure --prefix=/usr
[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
[root@s143 Python-2.7.18]# make install
[root@s143 Python-2.7.18]# python -V
Python 2.7.18
[root@s143 opt]# wget https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz
[root@s143 opt]# tar -zxvf Python-3.8.8.tgz
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
[root@s143 Python-3.8.8]# make
…
if test `uname -s` = Darwin; then
cp python-config.py python-config;
fi
[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
[root@s143 Python-3.6.10]# python3 -V
Python 3.8.8
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.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!