之前遇到很多人配置yum时候系统的yum不可用,直到自己也遇到决定总结一下自己的办法
参考了很多网上的资料,虽然解决了 但是废了好长时间。现在来个清晰明了的解决过程
当我使用yum时候出现如下错误
[root@woniusnail ~]# 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, Feb 5 2018, 03:00:27) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq
有人说可能是python版本导致的,所以我查了一下
[root@jrfwserver2 ~]# whereis python python: /usr/bin/python2.4 /usr/bin/python /usr/lib/python2.4 /usr/include/python2.4 /usr/share/man/man1/python.1.gz [root@jrfwserver2 ~]# vim /usr/bin/yum #!/usr/bin/python ###和上面的版本一致即可 import sys try: import yum except ImportError: print >> sys.stderr, """\ There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: %s 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: %s If you cannot solve this problem yourself, please go to the yum faq at: http://wiki.linux.duke.edu/YumFaq """ % (sys.exc_value, sys.version) sys.exit(1) sys.path.insert(0, '/usr/share/yum-cli') try: import yummain yummain.user_main(sys.argv[1:], exit_code=True) except KeyboardInterrupt, e: print >> sys.stderr, "\n\nExiting on user cancel." sys.exit(1)
结果 :没问题 有的朋友可能到这里就已经修复了但是我的还没有
呐,上绝招 把python和yum全部卸载重装
当然 你要先确定你的设备上没有依赖python的程序,没有再卸载,基本你自己的机器有啥东西你总该清楚吧。
卸载python,如果有重要业务依赖python运行就忽略这步 [root@woniusnail]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ###卸载python并解除关联 [root@woniusnail]# whereis python |xargs rm -rfv ###删除python的文件 [root@woniusnail]# rpm -qa | grep python ###没结果表示卸载成功 [root@woniusnail]# whereis python ###没结果表示删除成功 卸载yum [root@woniusnail]# rpm -qa|grep yum | xargs rpm -ev --allmatches --nodeps [root@woniusnail]# whereis yum | xargs rm -rfv [root@woniusnail]# rpm -qa | grep yum ###没结果表示卸载成功 [root@woniusnail]# whereis yum ###没结果表示删除成功
卸载完了,接下来安装。
先去软件包仓库找对应的软件包。注意查一下你的系统版本
[root@jrfwserver2 ~]# uname -a Linux jrfwserver2 2.6.18-194.el5xen #1 SMP Tue Mar 16 22:01:26 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
我的带el5 所以我找的软件包都是el5的,一定要对应的版本,如果不会取舍软件包那就把python和yum开头的都下载了,这样一定不会错,以下是我安装好的软件包。
python-elementtree-1.2.6-5 python-dmidecode-3.10.8-4.el5 python-sqlite-1.1.7-1.2.1 python-ldap-2.2.0-2.1 python-imaging-1.1.5-5. python-docs-2.4.3- python-iniparse-0.2.3-4.el5 python-urlgrabber-3.1.0-5. python-numeric-23.7-2.2.2 python-virtinst-0.400.3-9.el5 python-2.4.3-27.el5 yum-3.2.22-26.el5.centos yum-security-1.1.16-13.el5 yum-metadata-parser-1.1.2-3.el5.centos yum-fastestmirror-1.1.16-14.el5.centos.1
在你的机器上新建一个目录,把下载好的软件包都放进去,然后进入目录执行 rpm -Uvh * 升级安装所有软件包,如果出现依赖问题或者文件冲突问题,可以选择强制安装;
强制安装命令:rpm -ivh * –force 如果你前面操作没问题基本用不上这个
等待安装完成,测试一下yum命令,如果你重装了python 那也测试一下python命令。
到此,问题解决。