Many time after upgrading your OS or any package you are getting this error while running any command with yum
############################
[root@bhagwat ~]# 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.3 (default, Jan 21 2015, 16:18:50)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]
#############################
This is related with python version of your system. You may have many versions of python installed in your PC & only one of them has the yum library installed.
SOLUTION -
Run the below command - It will show the current python path (In my case it is working with python 2.7)
[root@bhagwat yum.repos.d]# ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 Jan 13 15:55 /usr/bin/python -> /usr/local/bin/python2.7
Check the python version available at your /usr/bin
[root@bhagwat]# /usr/bin/python
python python2 python2.6 python2.6.6 python-pip
For each of your python version run below command
/usr/bin/python2.x
You'll get a python prompt. Run:
>>> import yum
Do this for every python binary until you find one that doesn't raise an ImportError at this step.
[root@bhagwat yum.repos.d]# /usr/bin/python2.6
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
>>>
Now, run as root:
ln -s /usr/bin/python2.6 /usr/bin/python
& Done....Your Issue is resolved
In case you are getting error "ln: creating symbolic link `/usr/bin/python': File exists"
Just run the below command
[root@bhagwat bin]# mv /usr/bin/python /usr/bin/python-origin
-----------------------------
[root@bhagwat bin]# ln -s /usr/bin/python2.6 /usr/bin/python