程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python version upgrade for Linux

編輯:Python

One 、 Preface

upgrade glibc According to INSTALL Upgrade instructions , requirement python edition 3.4 above . So you need to python Version upgrade .centos7 Default installed python Version is 2.7.5,python adopt yum Installation can only be installed 2.7.5 edition ,python3 Can pass yum install 3.6.8 edition . If you need a higher version , Can only be installed through source compilation . This blog post introduces how to upgrade the source code installation python and python3 edition , Source code compilation and installation requires that the operating system has been installed gcc. The environmental description is as follows :

  • operating system :centos7.6
  • python edition : Pre upgrade version 2.7.5, After upgrading 2.7.18
  • python3 edition : Before upgrading 3.6.8, Upgraded version 3.8.8

Two 、python Installation steps

1、 View the current python edition

[[email protected] ~]# python -V
Python 2.7.5

2、yum install python

[[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

3、yum install python3

[[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!

3、 ... and 、python2 Upgrade steps

0、 Find the version that needs to be upgraded

python Official website ( Include python and python3 All versions ) Find the version that needs to be installed or upgraded .

1、 download python The new version

[[email protected] opt]# wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz

2、 Unzip package

[[email protected] opt]# tar -zxvf Python-2.7.18.tgz

3、 Precompiled package

[[email protected] opt]# cd Python-2.7.18
[[email protected] Python-2.7.18]# ./configure --prefix=/usr

4、 Compile the package

[[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

5、 Install package

[[email protected] Python-2.7.18]# make install

6、 Check the upgraded version

[[email protected] Python-2.7.18]# python -V
Python 2.7.18

Four 、python3 Upgrade steps

1、 Download installation package

[[email protected] opt]# wget https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz

2、 Unzip package

[[email protected] opt]# tar -zxvf Python-3.8.8.tgz

3、 precompile

Note that there will be a prompt after the compilation "If you want a release build with all stable optimizations active (PGO, etc),please run ./configure --enable-optimizations", add –enable-optimizations If precompiled, subsequent compilation will report errors “Could not import runpy module ”, as a result of gcc Outdated Version ,enable-optimizations Parameter requirements gcc edition 8.1.0 above .

[[email protected] opt]# cd Python-3.8.8
[[email protected] Python-3.8.8]# ./configure

4、 compile

[[email protected] Python-3.8.8]# make

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

5、 Compilation and installation

[[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

6、 Version check after upgrade

[[email protected] Python-3.6.10]# python3 -V
Python 3.8.8

5、 ... and 、QA

1、 install python3.8.8 It's a mistake zlib not available

  • Error message :zipimport.ZipImportError: can’t decompress data; zlib not available
  • Error reason : No installation zlib modular
  • Solution : install zlib modular
    [[email protected] bin]# yum install -y zlib*

2、 installed python after yum Report errors File “/usr/bin/yum”, line 30

  • Error message :File “/usr/bin/yum”, line 30
  • Error reason :python The soft connection points to python3 edition , and yum requirement python2 edition .
  • Solution 1: modify python Command soft connect to python2
    [[email protected] bin]# sln python2 python
    [[email protected] bin]# python -V
    Python 2.7.5
  • Solution 2: modify /usr/bin/yum file , take python Change it to python2

3、 installation is complete python after yum Installation error File “/usr/libexec/urlgrabber-ext-down”, line 28

  • Error message :File “/usr/libexec/urlgrabber-ext-down”, line 28
  • Error reason :yum The download program depends on python2
  • Solution 1: modify python Command soft connect to python2
  • Solution 2: modify /usr/libexec/urlgrabber-ext-down file , take python Change it to python2

4、 Upgrade to python2.7.18 Report a mistake later No module named rpm

  • Error message :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
  • Error reason :python2.7.18 yes python2 Latest version , It has been removed yum Support for ,centos8 By default dnf Package installation tools .
  • Solution : From the other centos7 The server copies one python2.7.5 To the server /usr/bin Under the table of contents , Then rebuild python Soft link .

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved