Centos – Installing Python 2.7 broke “yum”

centospythonyum

I installed Python 2.7 and pointed /usr/bin/python to /usr/local/bin/python2.7

After installing Python 2.7, I get the following error message every time I use yum

> sudo yum install setuptools
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.2 (default, Dec 25 2011, 19:13:04) 
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)]

If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://wiki.linux.duke.edu/YumFaq

How do I get yum working with Python 2.7 on CentOS?

Best Answer

You can edit the yum (/usr/bin/yum) call to python like:

#!/usr/bin/python2.4

Make a backup first ;-)