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


目录
打赏
0
0
0
0
344
分享
相关文章
Python执行Shell命令并获取结果:深入解析与实战
通过以上内容,开发者可以在实际项目中灵活应用Python执行Shell命令,实现各种自动化任务,提高开发和运维效率。
58 20
使用Python执行Shell命令并获取结果
在实际应用中,可以根据需要选择适当的参数和方法来执行Shell命令,并处理可能出现的各种情况。无论是系统管理、自动化任务还是数据处理,掌握这些技巧都将极大地提高工作效率。
74 12
yum 命令下载软件包到本地
在 Linux 系统中,使用 `yum` 命令可以下载软件包但不安装。通过 `yum` 的下载缓存功能,可以快速获取所需软件包。常用命令包括:`yum list available` 列出可安装的软件包,`yum download nginx` 下载特定软件包,`yum download nginx-1.18.0` 下载特定版本,`yum download -resolve nginx` 下载软件包及其依赖,`yum download nginx -d /path/to/download/directory` 指定下载目录
353 11
yum 命令下载软件包到本地
在 Linux 系统中,使用 yum 命令可以下载软件包但不安装。通过 yum 的下载缓存功能,可以快速获取软件包。常用命令包括:`yum list available` 列出可安装的软件包,`yum download nginx` 下载特定软件包,`yum download nginx-1.18.0` 下载特定版本,`yum download -resolve nginx` 下载软件包及其依赖,`yum download nginx -d /path/to/download/directory` 指定下载目录
253 1
|
4月前
|
Python PDB命令介绍
【10月更文挑战第15天】 使用PDB的方式有两种,其中一种是在脚本中添加代码,不觉得这种方式比print好在哪里,所以这种方式此文不表。这里我们只学习PDB的命令行使用方式
75 4
pytorch学习一(扩展篇):miniconda下载、安装、配置环境变量。miniconda创建多版本python环境。整理常用命令(亲测ok)
这篇文章是关于如何下载、安装和配置Miniconda,以及如何使用Miniconda创建和管理Python环境的详细指南。
883 0
pytorch学习一(扩展篇):miniconda下载、安装、配置环境变量。miniconda创建多版本python环境。整理常用命令(亲测ok)
Linux yum 命令
10月更文挑战第1天
82 2
python环境学习:pip介绍,pip 和 conda的区别和联系。哪个更好使用?pip创建虚拟环境并解释venv模块,pip的常用命令,conda的常用命令。
本文介绍了Python的包管理工具pip和环境管理器conda的区别与联系。pip主要用于安装和管理Python包,而conda不仅管理Python包,还能管理其他语言的包,并提供强大的环境管理功能。文章还讨论了pip创建虚拟环境的方法,以及pip和conda的常用命令。作者推荐使用conda安装科学计算和数据分析包,而pip则用于安装无法通过conda获取的包。
257 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等