草庐IT

Linux之python版本升级

恒悦sunsite 2023-07-18 原文

一、前言

  升级glibc的时候根据INSTALL升级说明,要求python版本3.4以上。所以需要对python版本进行升级。centos7默认安装的python版本为2.7.5,python通过yum安装也只能安装2.7.5版本,python3可以通过yum安装3.6.8版本。如果需要更高的版本,只能通过源码编译安装。此博文介绍源码安装方式升级python和python3版本,源码编译安装要求操作系统已经安装了gcc。环境说明如下:

  • 操作系统:centos7.6
  • python版本:升级前版本2.7.5,升级后2.7.18
  • python3版本:升级前3.6.8,升级后版本3.8.8

二、python安装步骤

1、查看当前python版本

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

2、yum安装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安装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!

三、python2升级步骤

0、查找需要升级的版本

python官网(包括python和python3所有的版本)查找需要安装或者升级的版本。

1、下载python新版本

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

2、解压软件包

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

3、预编译软件包

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

4、编译软件包

[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、安装软件包

[root@s143 Python-2.7.18]# make install

6、检查升级后的版本

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

四、python3升级步骤

1、下载安装包

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

2、解压软件包

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

3、预编译

注意在编译结束后会有提示"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以上。

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

4、编译

[root@s143 Python-3.8.8]# make

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

5、编译安装

[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、升级后版本检查

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

五、QA

1、安装python3.8.8的时候报错zlib not available

  • 报错信息:zipimport.ZipImportError: can’t decompress data; zlib not available
  • 报错原因:没有安装zlib模块
  • 解决方案:安装zlib模块
    [root@s143 bin]# yum install -y zlib*

2、安装完python之后yum报错File “/usr/bin/yum”, line 30

  • 报错信息:File “/usr/bin/yum”, line 30
  • 报错原因:python软连接指向了python3版本,而yum要求python2版本。
  • 解决方案1:修改python命令软连接到python2
    [root@s143 bin]# sln python2 python
    [root@s143 bin]# python -V
    Python 2.7.5
  • 解决方案2:修改/usr/bin/yum文件,将python改为python2

3、安装完成python之后yum安装报错File “/usr/libexec/urlgrabber-ext-down”, line 28

  • 报错信息:File “/usr/libexec/urlgrabber-ext-down”, line 28
  • 报错原因:yum下载程序依赖python2
  • 解决方案1:修改python命令软连接到python2
  • 解决方案2:修改/usr/libexec/urlgrabber-ext-down文件,将python改为python2

4、升级到python2.7.18后报错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
  • 报错原因:python2.7.18是python2的最新版本,已经移除了对yum的支持,centos8默认使用dnf软件包安装工具。
  • 解决方案:从其他centos7服务器拷贝一个python2.7.5到服务器/usr/bin目录下,然后重建python软链接。

有关Linux之python版本升级的更多相关文章

  1. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  2. ruby - 通过 rvm 升级 ruby​​gems 的问题 - 2

    尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub

  3. ruby-on-rails - 项目升级后 Pow 不会更改 ruby​​ 版本 - 2

    我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby​​版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby​​版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘

  4. ruby - 如何在 Lion 上安装 Xcode 4.6,需要用 RVM 升级 ruby - 2

    我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121

  5. ruby-on-rails - 在 ruby​​ .gemspec 文件中,如何指定依赖项的多个版本? - 2

    我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这

  6. ruby-on-rails - 如果我将 ruby​​ 版本 2.5.1 与 rails 版本 2.3.18 一起使用会怎样? - 2

    如果我使用ruby​​版本2.5.1和Rails版本2.3.18会怎样?我有基于rails2.3.18和ruby​​1.9.2p320构建的rails应用程序,我只想升级ruby的版本,而不是rails,这可能吗?我必须面对哪些挑战? 最佳答案 GitHub维护apublicfork它有针对旧Rails版本的分支,有各种变化,它们一直在运行。有一段时间,他们在较新的Ruby版本上运行较旧的Rails版本,而不是最初支持的版本,因此您可能会发现一些关于需要向后移植的有用提示。不过,他们现在已经有几年没有使用2.3了,所以充其量只能让更

  7. ruby-on-rails - 获取 inf-ruby 以使用 ruby​​ 版本管理器 (rvm) - 2

    我安装了ruby​​版本管理器,并将RVM安装的ruby​​实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby​​。有没有办法让emacs像shell一样尊重ruby​​的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el

  8. ruby - 在不使用 RVM 的情况下在 Mac 上卸载和升级 Ruby - 2

    我最近决定从我的系统中卸载RVM。在thispage提出的一些论点说服我:实际上,我的决定是,我根本不想担心Ruby的多个版本。我只想使用1.9.2-p290版本而不用担心其他任何事情。但是,当我在我的Mac上运行ruby--version时,它告诉我我的版本是1.8.7。我四处寻找如何简单地从我的Mac上卸载这个Ruby,但奇怪的是我没有找到任何东西。似乎唯一想卸载Ruby的人运行linux,而使用Mac的每个人都推荐RVM。如何从我的Mac上卸载Ruby1.8.7?我想升级到1.9.2-p290版本,并且我希望我的系统上只有一个版本。 最佳答案

  9. Python 相当于 Perl/Ruby ||= - 2

    这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Pythonconditionalassignmentoperator对于这样一个简单的问题表示歉意,但是谷歌搜索||=并不是很有帮助;)Python中是否有与Ruby和Perl中的||=语句等效的语句?例如:foo="hey"foo||="what"#assignfooifit'sundefined#fooisstill"hey"bar||="yeah"#baris"yeah"另外,类似这样的东西的通用术语是什么?条件分配是我的第一个猜测,但Wikipediapage跟我想的不太一样。

  10. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

随机推荐