《LINUX實操:Python升級導致yum不可用 “ No module named yum”》要點:
本文介紹了LINUX實操:Python升級導致yum不可用 “ No module named yum”,希望對您有用。如果有疑問,可以聯系我們。
最近在看Python,虛擬機裝的是CentOS 6.6,自帶的Python版本是2.6.6,盤算升級到2.7.
我的升級過程年夜致如下:
下載2.7源碼包https://www.python.org/downloads/source/
卸載舊的python,rpm -e python
編譯安裝python2.7
整個過程沒有遇到問題,但升級完后,再用yum安裝軟件時報如下差錯
[root@localhost python]# 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.13 (r266:84292, Jan 22 2014, 09:37:14)?
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
?
If you cannot solve this problem yourself, please go to?
the yum faq at:
? http://yum.baseurl.org/wiki/Faq
yum不可用了,這下問題就大了,spacer.gif沒有yum,安裝rpm包特別費勁.
開始百度關鍵字“No module named yum”,出來很多帖子和博客,博客上邊說的大概意思就是yum就基于python的,升級python后,yum與高版本的python不兼容,導致yum無法使用.博客上給出的辦法都是修改/usr/bin/yum文件的頭部,把/usr/bin/python修改為/usr/bin/python2.6就可以了,但我的情況是我把舊的python已經卸載了,于是又開始安裝2.6版本的python.
安裝好2.6.6版本的之后以為就好了,但是還是報有錯誤:
[root@localhost python]# 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.6.6 (r266:84292, Jan 22 2014, 09:37:14)?
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
?
If you cannot solve this problem yourself, please go to?
the yum faq at:
? http://yum.baseurl.org/wiki/Faq
這就奇怪了,都已經把舊版本的裝上了,還是不行.這時看到一篇博客是把python和yum都全部卸載后重新安裝的.想想這也是個方法于是就又全部下載
whereis python |xargs rm -rf
rpm -e --nodeps python
卸載后重新安裝,從光盤鏡像里找到python和yum的包
rpm -ivh --nodeps python*
rpm -ivh --nodeps yum*
這次總該好了吧,驗證一下
[root@localhost python]# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:37:14)?
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yum
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
? File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 23, in <module>
? ? import rpm
ImportError: No module named rpm
還是報錯.不過這次錯誤變了,釀成了“No module named rpm”
再次百度,看到有人說是缺少包:rpm -ivh rpm-python-4.8.0-37.el6.i686.rpm
安裝上面的包后一切yum恢復正常了.
那問題又來了豈非因為yum就不升級python版本嗎?當然不是.其實是我在安裝新版python的時候把舊版本的也卸載了才導致這樣的問題.
后來在不卸載2.6版本的python是,重新編譯安裝2.7版本,安裝成功而且yum仍然可用.
本文永遠更新鏈接地址:
更多LINUX教程,盡在維易PHP學院專欄。歡迎交流《LINUX實操:Python升級導致yum不可用 “ No module named yum”》!
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/8877.html