误卸载python导致yum无法使用事件(总结)

由于服务器需要升级python,参照了一篇坑爹的文章卸载了旧版python
# 卸载旧的python
sudo rpm -evf --nodeps python
导致yum无法使用 

 
yum -v
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.3 (#1, Feb 3 2012, 15:37:12)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)]
If you cannot solve this problem yourself, please go to
the yum faq at:http://wiki.linux.duke.edu/YumFaq

由于yum是基于python
centos6.2默认使用python2.6.6,我又源码安装了一遍python2.6.6,
修改了vi /usr/bin/yum
#/usr/bin/python修改为#/usr/bin/python2.6
执行yum-v还是不行~~

于是就从centos6.2光盘找python和yum的rpm包安装,一番尝试之后,发现有N个package需要重新安装,这里就不写尝试过程,终于搞定!

解决方法如下

cnetos6.2*64光盘rpm包地址http://mirrors.ustc.edu.cn/centos/6.2/os/x86_64/Packages/

需要安装这几个包
python-2.6.6-29.el6.x86_64.rpm
python-devel-2.6.6-29.el6.x86_64.rpm
python-iniparse-0.3.1-2.1.el6.noarch.rpm
python-setuptools-0.6.10-3.el6.noarch.rpm
python-urlgrabber-3.9.1-8.el6.noarch.rpm
rpm-python-4.8.0-19.el6.x86_64.rpm
yum-3.2.29-22.el6.centos.noarch.rpm
yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
python-pycurl-7.19.0-8.el6.x86_64.rpm

注意rpm命令,必须要追加 –replacepkgs 参数,强制其重新安装,否则rpm会报告说package已安装。
rpm -Uvh --replacepkgs ***.rpm
如果仍然无法运行Yum,则运行 Python,import yum,查询下缺少什么东西。

python
Python 2.6.6 (r266:84292, Dec 7 2011, 20:48:22)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>import yum

//会提示相关的错误,查找对应的rpm,装上即可,重复此过程,直到 yum 正常


关于yum异常问题处理之“土”方法:

#vim /usr/bin/yum  

将首行显示的 !#/usr/bin/python 修改为 !#/usr/bin/python2.6(我的系统默认安装的是python2.6,你也可以用whereis python 查看升级前和升级后的版本)  


#############################

源码包安装了 python2.7  想还原为系统默认

whereis python   

找到2.7 的python全部删掉,然后执行,yum 如果正常,则看python是否正常

结果有问题:

python  

  /usr/local/bin/python No such file or directory" 

做个软连接就ok 

pwd   /usr/local

ln -s /usr/local/bin/python2.6  python