2023年11月28日发(作者:)
linux下⾯升级Python版本并修改yum属性信息
最近需要在linux下使⽤python,故需要升级⼀下python版本,上⽹查询了⼀下相关资料,更新了⼀下linux下⾯的python环境,记录如下:
linux下⾯升级 Python版本并修改yum属性信息
⾸先linux下查询python版本
[root@test30 chengshaoling]# python -V
Python 2.7.5
1.最新版本python下载安装
下载新版本的python
python主站相关地址:
[root@test30 makePython]# wget /downloads/release/python-373/ #下载的不完整,⼜⼿动⽹页下
载,上传到Linux系统的
解压缩 以及编译
[root@test30 makePython]# tar -xvf
[root@test30 makePython]# cd Python-2.7.12
[root@test30 Python-2.7.12]# ./configure --prefix=/usr/local/python27 #我运⾏了 ./configure 后⼜运⾏了./configure --
prefix=/usr/local/python37
[root@test30 Python-2.7.12]# make
[root@test30 Python-2.7.12]# make install
再次查看python版本,系统展现版本未更新
[root@test30 Python-2.7.12]# python -V
Python 2.7.5
2. python多版本共存解决
下⾯来解决这个问题
把原来的python重命名成python_old,注意不要删除
[root@test30 Python-2.7.12]# mv /usr/bin/python /usr/bin/python_old
[root@test30 Python-2.7.12]# ln -s /usr/local/python37/bin/python3 /usr/bin/python
再查看⼀下版本
[root@test30 Python-2.7.12]#python -V
Python 3.7.3
成功更新python版本
3.解决yum的python版本问题
还有最后⼀个问题要解决,因为yum是使⽤的python2.7.5的版本,所以 还需要修改⼀下yum的python版本(利⽤前⾯重命名的python_old⽂
件夹的内容)
[root@test30 Python-2.7.12]# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.12 (default, Nov 29 2016, 11:07:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
If you cannot solve this problem yourself, please go to
the yum faq at:
修改yum⽂件中配置的python程序位置:
[root@test30 Python-2.7.12]# cd /usr/bin/
[root@test30 bin]# vi yum
#!/usr/bin/python_old #修改此处为原始python程序的位置 #后边不能写注释,会出问题 不知道为啥
import sys
try:
import yum
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
你需要给出命令
Usage: yum [options] COMMAND
List of Commands:
check Check for problems in the rpmdb
check-update 检查是否有软件包更新
clean 删除缓存的数据
deplist 列出软件包的依赖关系
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade downgrade a package
erase 从系统中移除⼀个或多个软件包
groupinfo 显⽰组的详细信息
groupinstall 向系统中安装⼀组软件包
grouplist 列出可安装的组
groupremove 从系统中移除⼀组软件包
help 显⽰⽤法信息
history Display, or use, the transaction history
info 显⽰关于软件包或组的详细信息
配置⽂件路径
-R [minutes], --randomwait=[minutes]
命令最长等待时间
-d [debug level], --debuglevel=[debug level]
调试输出级别
--showduplicates 在 list/search 命令下,显⽰仓库⾥重复的条⽬。
-e [error level], --errorlevel=[error level]
错误输出级别
--rpmverbosity=[debug level name]
debugging output level for rpm
-q, --quiet 安静的操作
-v, --verbose verbose operation
-y, --assumeyes 回答所有的问题为是
--assumeno answer no for all questions
--version 显⽰ Yum 版本信息并退出
--installroot=[path] 设置⽬标根⽬录
--enablerepo=[repo] 启⽤⼀个或多个仓库(⽀持通配符)
--disablerepo=[repo] 禁⽤⼀个或多个仓库(⽀持通配符)
-x [package], --exclude=[package]
⽤全名或通配符排除软件包
--disableexcludes=[repo]
禁⽌从主配置,从仓库或者从任何位置排除
--obsoletes 升级时考虑软件包取代关系
--noplugins 禁⽤ Yum 插件
--nogpgcheck 禁⽤ gpg 签名检测
--disableplugin=[plugin]
禁⽤指定名称的插件
--enableplugin=[plugin]
enable plugins by name
--skip-broken 跳过有依赖问题的软件包
⾄此,python升级完成
参考:/s/blog_
参考:/jiangshan35/article/details/69568271
参考:/eleganthua/p/
总结:python 升级;默认调⽤改为升级后的Python;但是,yum不能配套使⽤升级后的Python,yum 改为默认路径为⽼的Python包路径;
发布评论