Linux_yum / Python 報錯

來源:互聯網
上載者:User

原文地址 :  https://www.52os.net/articles/no-module-named-yum-issue.html

伺服器是centos 5.9 64位的系統,因為好幾個人一起用,不清楚其它人做了什麼。
任何yum操作都會報錯,錯誤資訊如下:

[root@LB1603 log]# yum --versionThere was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was:No module named yumPlease install a package which provides this module, orverify that the module is installed correctly.It's possible that the above module doesn't match thecurrent version of Python, which is:2.7 (r27:82500, Sep  9 2014, 04:09:22) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]If you cannot solve this problem yourself, please go to the yum faq at:http://wiki.linux.duke.edu/YumFaq

錯誤原因:在yum 的faq中提到,yum是python的一個模組,如果yum所依賴的python版本不一致,就會出現這個問題。

先看一下python的版本:

[root@LB1603 log]# whereis pythonpython: /usr/bin/python /usr/bin/python.bak /usr/bin/python2.4 /usr/lib/python2.4 /usr/local/bin/python2.7 /usr/local/bin/python2.7-config /usr/local/bin/python /usr/local/lib/python2.7 /usr/include/python2.4 /usr/share/man/man1/python.1.gz

有兩個版本,分別試著匯入一下yum包:

root@LB1603 log]# pythonPython 2.7 (r27:82500, Sep  9 2014, 04:09:22) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import yum Traceback (most recent call last):File "<stdin>", line 1, in <module>ImportError: No module named yum

提示 No module named yum 和直接運行yum的報錯一致,換個版本試下:

[root@LB1603 log]# python2.4 Python 2.4.3 (#1, Jan  9 2013, 06:47:03) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import yum

成功匯入了,原因找到了,解決方案很簡單:

vim /usr/bin/yum

把開頭 #!/usr/bin/python 改為 #!/usr/bin/python2.4 儲存退出即可。

在python的路徑中看到有一個/usr/bin/python.bak的備份檔案,看下了下版本是python2.4,基本上可以肯定是有人升級了python,導致了這個問題

參考文章:
http://blog.csdn.net/ei__nino/article/details/8495295
http://yum.baseurl.org/wiki/Faq

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.