centos6升级了python的版本,导致yum运行出现No module named yum,而无法使用
原因:
跟yum匹配的python版本是系统带的2.6版本,而现在python版本被更新到2.7
其他用到python的软件也可能会出现这种问题,处理方法一样:如下解决方法
现象:
[root@localhost ~]# yum install http-devel -y
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, Jan 10 2017, 10:36:02)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
解决办法:
检查之前的版本python2.6是否存在:
[root@localhost ~]# ll /usr/bin/python*
lrwxrwxrwx 1 root root 24 Jan 10 10:36 /usr/bin/python -> /usr/local/bin/python2.7
lrwxrwxrwx. 1 root root 6 Aug 25 21:29 /usr/bin/python2 -> python
-rwxr-xr-x 1 root root 9032 Jul 24 2015 /usr/bin/python2.6
修改yum启动脚本:
vim /usr/bin/yum
把第一行的#!/usr/bin/python
修改为:
#!/usr/bin/python2.6
检查是否可以使用:
[root@localhost ~]# yum list
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
另外一种方法,网上找的,未测试,供参考:
首先找到你安装Centos的光盘或者ISO文件,拷贝如下文件到系统中:
(或者找一个yum源,下载以下包也可以,只要系统版本一样即可,例如:http://mirrors.ustc.edu.cn/centos/)
python-2.6.6-36.el6.x86_64.rpm
python-urlgrabber-3.9.1-8.el6.noarch.rpm
python-devel-2.6.6-36.el6.x86_64.rpm
python-libs-2.6.6-36.el6.x86_64.rpm
yum-3.2.29-40.el6.centos.noarch.rpm
具体版本号,根据你系统盘或者ISO提供为准。我是拷贝到了如下目录
/usr/local/rpm/Python-2.6.6
执行安装
cd /usr/local/rpm/Python-2.6.6/
rpm -Uvh --replacepkgs *.rpm
python-2.6.6-36.el6.x86_64.rpm
python-urlgrabber-3.9.1-8.el6.noarch.rpm
python-devel-2.6.6-36.el6.x86_64.rpm
python-libs-2.6.6-36.el6.x86_64.rpm
yum-3.2.29-40.el6.centos.noarch.rpm
具体版本号,根据你系统盘或者ISO提供为准。我是拷贝到了如下目录
/usr/local/rpm/Python-2.6.6
执行安装
cd /usr/local/rpm/Python-2.6.6/
rpm -Uvh --replacepkgs *.rpm