天天看點

記一次python更新版本遇到的事

由于伺服器需要更新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.2CD光牒找python和yum的rpm包安裝,一番嘗試之後,發現有N個package需要重新安裝,這裡就不寫嘗試過程,終于搞定!

解決方法如下

cnetos6.2*64CD光牒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  

做個軟連接配接就ok 

pwd   /usr/local

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

      本文轉自crazy_charles 51CTO部落格,原文連結:http://blog.51cto.com/douya/1425492,如需轉載請自行聯系原作者