How to Solve Centos Yum Error: No module named yum

centos reports an error when executing yum

[root@localhost ~]# 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.8 (default, Nov 24 2015, 15:31:38)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]

If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq

Most of them are caused by python upgrade

Check python version

[root@localhost ~]# ls /usr/bin/|grep python
abrt-action-analyze-python
python
python2
python2.6.6
python-config

Modify the python interpreter address

vim /usr/bin/yum Change the first line #! /usr/bin/python to #! /usr/bin/python2.6.6

If you still get an error, you need to check if python 2.6.6 is working properly

Enter the following command in the python interactive terminal.

>>> import yum
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ImportError: No module named yum

To see if there are yum modules

ls /usr/lib/python2.6/site-packages/yum to see if there is anything under this directory, if there is nothing, then there is nothing under it

If this directory exists, check if python 2.6.6 can import other modules properly

For example: import os

If it doesn’t work, the directory /usr/lib64/python2.6 is corrupt or unusable.

If it is gone, you can only copy one from another server, so that it works

Similar Posts: