python升级导致yum命令无法使用的解决办法

简介:

1、报错信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
[root@sa ~] # yum install prce -y
There was a problem importing one of the Python modules required to run yum. 
The error leading to this problem was:
    libxml2.so.2: cannot  open  shared object  file : No such  file  or directory
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.6.6 (r266:84292, Oct 12 2012, 14:23:48) 
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]
If you cannot solve this problem yourself, please go to the yum faq at:
   http: //yum .baseurl.org /wiki/Faq


1
2
3
4
5
6
7
8
9
10
11
[root@sa yum.repos.d] # yum repolist
There was a problem importing one of the Python modules required to run yum. 
The error leading to this problem was:
    libxml2.so.2: cannot  open  shared object  file : No such  file  or directory
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.6.6 (r266:84292, Oct 12 2012, 14:23:48) 
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]
If you cannot solve this problem yourself, please go to the yum faq at:  
http: //yum .baseurl.org /wiki/Faq

------------------------------------------------------------------------------------------------------------------------

错误原因:错误信息描述为 yum 所依赖的python 不相符,请安装相对应的python即可


2、查看yum版本

1
2
3
[root@develop  local ] # rpm -qa |grep yum
yum-3.2.8-9.el5.centos.1
yum-metadata-parser-1.1.2-2.el5



3、查看python版本

1
2
3
4
[root@develop  local ] # whereis python  
python:  /usr/bin/python2 .4  /usr/bin/python  /usr/lib/python2 .4 
/usr/local/bin/python2 .6  /usr/local/bin/python2 .6-config  /usr/local/bin/python 
/usr/local/lib/python2 .6  /usr/share/man/man1/python .1.gz


果然装了两个版本python


4、执行python,查看到使用2.6.1的版本

[plain]view plaincopyprint?

[root@develop local]# python  

Python 2.6.1 (r261:67515, Aug 7 2010, 11:36:17)  

[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2  

Type "help", "copyright", "credits" or "license" for more information.  

>>>  


5、猜测yum调用了高版本的python。


6、解决方法:

查找yum和 yum-updatest文件,并编辑此py文件

1
2
3
4
[root@develop  local ] # which yum  
/usr/bin/yum  
[root@develop  local ] # vi /usr/bin/yum  
[root@develop  local ] # vi /usr/bin/yum-updatest


#!/usr/bin/python

改为:

#!/usr/bin/python2.4


然后保存OK.


如果不修改/usr/bin/yum ,则yum无法使用

如果不修改/usr/bin/yum-updatest  会出现如下错误

 File "/usr/sbin/yum-updatesd", line 35, in

    import dbus

ImportError: No module named dbus


当然,修改完后记着

1
2
3
[root@localhost google_appengine] # /sbin/service yum-updatesd restart  
Stopping yum-updatesd:                                     [FAILED]  
Starting yum-updatesd:                                     [ OK   ]


补充:yum基于python写的。


本文转自 Mr_sheng 51CTO博客,原文链接:http://blog.51cto.com/sf1314/2062329


相关文章
|
2月前
|
监控 安全 程序员
Python日志模块配置:从print到logging的优雅升级指南
从 `print` 到 `logging` 是 Python 开发的必经之路。`print` 调试简单却难维护,日志混乱、无法分级、缺乏上下文;而 `logging` 支持级别控制、多输出、结构化记录,助力项目可维护性升级。本文详解痛点、优势、迁移方案与最佳实践,助你构建专业日志系统,让程序“有记忆”。
256 0
|
7月前
|
SQL 安全 算法
解读 Python 3.14:模板字符串、惰性类型、Zstd压缩等7大核心功能升级
Python 3.14 引入了七大核心技术特性,大幅提升开发效率与应用安全性。其中包括:t-strings(PEP 750)提供更安全灵活的字符串处理;类型注解惰性求值(PEP 649)优化启动性能;外部调试器API标准化(PEP 768)增强调试体验;原生支持Zstandard压缩算法(PEP 784)提高效率;REPL交互环境升级更友好;UUID模块扩展支持新标准并优化性能;finally块语义强化(PEP 765)确保资源清理可靠性。这些改进使Python在后端开发、数据科学等领域更具竞争力。
308 5
解读 Python 3.14:模板字符串、惰性类型、Zstd压缩等7大核心功能升级
|
6月前
|
IDE 开发工具 Python
魔搭notebook在web IDE下,使用jupyter notebook,python扩展包无法更新升级
魔搭notebook在web IDE下,使用jupyter notebook,python扩展包无法更新升级,不升级无法使用,安装python扩展包的时候一直停留在installing
177 4
|
安全 网络安全 文件存储
思科设备巡检命令Python脚本大集合
【10月更文挑战第18天】
540 1
思科设备巡检命令Python脚本大集合
|
9月前
|
安全 Ubuntu 网络安全
宝塔面板升级python3
Python 是一种广泛使用的高级编程语言,因其简洁的语法和丰富的库而受到开发者的喜爱。在许多Web应用程序和后端开发环境中,Python已成为重要工具。使用宝塔面板时,保持Python更新至关重要。本文介绍如何在服务器上安全升级Python:从环境准备、检查当前版本、安装工具包、下载并编译新版本、配置环境变量到测试新版本,确保升级顺利进行。建议定期更新以利用新特性和性能改进,并备份数据以防万一。
523 6
|
11月前
|
运维 Shell 数据库
Python执行Shell命令并获取结果:深入解析与实战
通过以上内容,开发者可以在实际项目中灵活应用Python执行Shell命令,实现各种自动化任务,提高开发和运维效率。
331 20
|
12月前
|
分布式计算 MaxCompute 对象存储
|
11月前
|
安全 Shell 数据处理
使用Python执行Shell命令并获取结果
在实际应用中,可以根据需要选择适当的参数和方法来执行Shell命令,并处理可能出现的各种情况。无论是系统管理、自动化任务还是数据处理,掌握这些技巧都将极大地提高工作效率。
380 12
|
Python
Python PDB命令介绍
【10月更文挑战第15天】 使用PDB的方式有两种,其中一种是在脚本中添加代码,不觉得这种方式比print好在哪里,所以这种方式此文不表。这里我们只学习PDB的命令行使用方式
341 4
|
机器学习/深度学习 缓存 Linux
python环境学习:pip介绍,pip 和 conda的区别和联系。哪个更好使用?pip创建虚拟环境并解释venv模块,pip的常用命令,conda的常用命令。
本文介绍了Python的包管理工具pip和环境管理器conda的区别与联系。pip主要用于安装和管理Python包,而conda不仅管理Python包,还能管理其他语言的包,并提供强大的环境管理功能。文章还讨论了pip创建虚拟环境的方法,以及pip和conda的常用命令。作者推荐使用conda安装科学计算和数据分析包,而pip则用于安装无法通过conda获取的包。
1582 0

推荐镜像

更多