2021-05-12 14:32:11
升級Python導致yum報錯
一天,需要在Linux伺服器上面安裝一個rpm包,結果執行yum命令的時候無論如何都會報錯,如下:
[root@test bin]# 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.10 (default, Sep 7 2015, 10:39:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
報錯資訊中提到:
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.10 (default, Sep 7 2015, 10:39:35)
所以懷疑和剛剛升級的Python有關係,但是也不能為了yum將剛剛升級的Python協助了啊,
我們進一步檢視:
[root@test bin]# strace yum
execve("/usr/bin/yum", ["yum"], [/* 30 vars */]) = 0
brk(0) = 0x1849000
........
stat("/usr/bin", {st_mode=S_IFDIR|0555, st_size=40960, ...}) = 0
stat("/usr/bin/yum", {st_mode=S_IFREG|0755, st_size=801, ...}) = 0
open("/usr/bin/yum.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/bin/yummodule.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/bin/yum.py", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/bin/yum.pyc", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/python2.7/yum", 0x7fff5cca59c0) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/python2.7/yum.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/python2.7/yummodule.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/python2.7/yum.py", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/python2.7/yum.pyc", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/local/lib/python2.7/plat-linux2/yum", 0x7fff5cca59c0) = -1 ENOENT (No such file or directory)
.....
write(2, "There was a problem importing on"..., 527There 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.10 (default, Sep 7 2015, 10:39:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
) = 527
write(2, "n", 1
) = 1
rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x343800f500}, {0x4e4a30, [], SA_RESTORER, 0x343800f500}, 8) = 0
brk(0x1907000) = 0x1907000
exit_group(1) = ?
[root@test bin]#
我們通過strace命令,發現紀錄檔中的下半部分,都是Python導致的錯誤,
然後想起原來系統中的Python是 2.66版本的,後來我將其升級成了2.7.10了
會不會就是這個問題導致的呢? 然後我從其他的伺服器(同版本)中下載下來一個2.66的Python,放到/usr/bin目錄下,並且重新命名為 python2.6
然後執行命令查詢yum的位置,並且vi開啟yum檔案,將第一行的Python改為 python2.6
將其他yum開頭的幾個指令碼也都做修改
[root@test bin]# which yum
/usr/bin/yum
[root@test bin]# vi yum
[root@test bin]# head -n 1 yum*
==> yum <==
#!/usr/bin/python2.6
==> yum-builddep <==
#!/usr/bin/python2.6 -tt
==> yum-config-manager <==
#!/usr/bin/python2.6 -tt
==> yum-debug-dump <==
#!/usr/bin/python2.6 -tt
==> yum-debug-restore <==
#!/usr/bin/python2.6 -tt
==> yumdownloader <==
#!/usr/bin/python2.6
==> yum-groups-manager <==
#!/usr/bin/python2.6 -tt
再次執行yum命令,問題解決!
更多YUM相關教學見以下內容:
RedHat 6.2 Linux修改yum源免費使用CentOS源 http://www.linuxidc.com/Linux/2013-07/87383.htm
設定EPEL YUM源 http://www.linuxidc.com/Linux/2012-10/71850.htm
Redhat 本地yum源設定 http://www.linuxidc.com/Linux/2012-11/75127.htm
yum的組態檔說明 http://www.linuxidc.com/Linux/2013-04/83298.htm
RedHat 6.1下安裝yum(圖文) http://www.linuxidc.com/Linux/2013-06/86535.htm
YUM 安裝及清理 http://www.linuxidc.com/Linux/2013-07/87163.htm
CentOS 6.4上搭建yum本地源 http://www.linuxidc.com/Linux/2014-07/104533.htm
本文永久更新連結地址:http://www.linuxidc.com/Linux/2015-12/126579.htm
相關文章