升級glibc的時候根據INSTALL升級說明,要求python版本3.4以上。所以需要對python版本進行升級。centos7默認安裝的python版本為2.7.5,python通過yum安裝也只能安裝2.7.5版本,python3可以通過yum安裝3.6.8版本。如果需要更高的版本,只能通過源碼編譯安裝。此博文介紹源碼安裝方式升級python和python3版本,源碼編譯安裝要求操作系統已經安裝了gcc。環境說明如下:
[[email protected] ~]# python -V
Python 2.7.5
[[email protected] ~]# 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
[[email protected] ~]# 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官網(包括python和python3所有的版本)查找需要安裝或者升級的版本。
[[email protected] opt]# wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
[[email protected] opt]# tar -zxvf Python-2.7.18.tgz
[[email protected] opt]# cd Python-2.7.18
[[email protected] Python-2.7.18]# ./configure --prefix=/usr
[[email protected] 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
[[email protected] Python-2.7.18]# make install
[[email protected] Python-2.7.18]# python -V
Python 2.7.18
[[email protected] opt]# wget https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz
[[email protected] opt]# tar -zxvf Python-3.8.8.tgz
注意在編譯結束後會有提示"If you want a release build with all stable optimizations active (PGO, etc),please run ./configure --enable-optimizations",加上–enable-optimizations預編譯的話後續編譯會報錯“Could not import runpy module ”,原因是gcc版本太低,enable-optimizations參數要求gcc版本8.1.0以上。
[[email protected] opt]# cd Python-3.8.8
[[email protected] Python-3.8.8]# ./configure
[[email protected] Python-3.8.8]# make
…
if test `uname -s` = Darwin; then
cp python-config.py python-config;
fi
[[email protected] Python-3.8.8]# make install
…
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2
[[email protected] Python-3.6.10]# python3 -V
Python 3.8.8