报错信息:
[root@localhost python]# yum clean all
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 (r27:82500, Jul 27 2018, 10:51:17)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)]
If you cannot solve this problem yourself, please go to
the yum faq at:
解决办法:
一、升级或卸载Python导致:
1、查看已安装python的版本,可能是当前系统存在多个python导致
[root@test
~]#
whereis python
python: /usr/bin/python2.6 /usr/bin/python /usr/bin/python2.6-config /usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6 /usr/share/man/man1/python.1.gz
[root@test
~]# vi
/usr/bin/yum
将 #!/usr/bin/python
修改为 #!/usr/bin/python2.6
如果是源代码安装的,默认路径是/usr/local/bin/python2.6,做个软链接即可
rm -rf
/usr/bin/python
ln -s
/usr/local/bin/python2.6 /usr/bin/python
二、完全重装python和yum
1、删除现有Python
[root@test
~]# rpm
-qa|grep python|xargs rpm -ev --allmatches --nodeps
##强制删除已安装程序及其关联
[root@test
~]#
whereis python |xargs rm -frv ##删除所有残余文件
##xargs,允许你对输出执行其他某些命令
[root@test
~]#
whereis python ##验证删除,返回无结果
2、删除现有的yum
[root@test
~]# rpm
-qa|grep yum|xargs rpm -ev --allmatches --nodeps
[root@test
~]#
whereis yum |xargs rm -frv
3、从http://mirrors.163.com/centos/7/os/x86_64/Packages/下载相应的包
python-2.7.5-68.el7.x86_64.rpm
python-backports-1.0-8.el7.x86_64.rpm
python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
python-chardet-2.2.1-1.el7_1.noarch.rpm
python-devel-2.7.5-68.el7.x86_64.rpm
python-iniparse-0.4-9.el7.noarch.rpm
python-ipaddress-1.0.16-2.el7.noarch.rpm
python-kitchen-1.1.1-5.el7.noarch.rpm
python-libs-2.7.5-68.el7.x86_64.rpm
python-pycurl-7.19.0-19.el7.x86_64.rpm
python-setuptools-0.9.8-7.el7.noarch.rpm
python-urlgrabber-3.10-8.el7.noarch.rpm
rpm-4.11.3-32.el7.x86_64.rpm
rpm-build-4.11.3-32.el7.x86_64.rpm
rpm-build-libs-4.11.3-32.el7.x86_64.rpm
rpm-devel-4.11.3-32.el7.x86_64.rpm
rpm-libs-4.11.3-32.el7.x86_64.rpm
rpm-python-4.11.3-32.el7.x86_64.rpm
rpm-sign-4.11.3-32.el7.x86_64.rpm
yum-3.4.3-158.el7.centos.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-aliases-1.1.31-45.el7.noarch.rpm
yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
yum-plugin-protectbase-1.1.31-45.el7.noarch.rpm
yum-utils-1.1.31-45.el7.noarch.rpm
libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
openssl-1.0.2k-12.el7.x86_64.rpm
openssl-devel-1.0.2k-12.el7.x86_64.rpm
openssl-libs-1.0.2k-12.el7.x86_64.rpm
openssl-static-1.0.2k-12.el7.x86_64.rpm
由于源中版本会更新,具体请查看URL中的版本再下载下来![root@test ~]# rpm -Uvh
--replacepkgs openssl*.rpm[root@test
~]# ln -s /usr/bin/openssl
/usr/local/bin/openssl
[root@test
~]# rpm
-Uvh --replacepkgs python*.rpm[root@test ~]# ln -s
/usr/bin/python /usr/local/bin/python[root@test ~]# rpm -Uvh --replacepkgs
python-chardet-2.2.1-1.el7_1.noarch.rpm python-kitchen-1.1.1-5.el7.noarch.rpm[root@test
~]# rpm -Uvh
--replacepkgs libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm[root@test ~]# rpm -Uvh
--replacepkgs rpm-*.rpm
[root@test
~]# rpm
-Uvh --replacepkgs yum*.rpm
可能之间还需要zlib和zlib-devel包,根据情况下载并安装!
三、运行python进行测试
[root@test
~]#
python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>>
如上,要是什么都没报,则说明OK啦~