I think I messed up my python config now yum wont work. I'm getting error 'No module named yum'. I have tried editing /usr/bin/yum and adding #!/usr/bin/python2.6 as the interpreter but this has not helped. I have put it back to its original settings /usr/bin/python.

[root@bin]# python --version
Python 2.7.14

[root@bin]# ls -l /usr/bin/python
lrwxrwxrwx 1 root root 18 Feb 21 09:08 /usr/bin/python -> /usr/bin/python2.6

[root@bin]# cat /etc/redhat-release
CentOS release 6.6 (Final)
  • Is Python 2.7.14 prepended to your $PATH? You can check with echo $PATH. If it is, remove it, make sure that you have Python 2.6, and try again. – Nasir Riley Feb 21 at 16:25

Your /usr/bin/python is still pointing at the original Python 2.6 shipped with CentOS 6, so that doesn't seem to be the problem. You can double check that with /usr/bin/python --version to confirm it works.

The most likely problem is that your Python 2.7 install overwrote some other file/directory in the shipped Python install from the system, probably something under /usr/lib/python, maybe a site-packages directory or similar.

You can use an rpm -V command ("V" for "verify") to ask the RPM package manager to tell you about which files were modified since a package was installed. For instance, to verify all the Python and Yum packages, use this command:

# rpm -Va 'python*' 'yum*'

Look at the rpm documentation for help with the output format, but in any case, if you see a "5" flag listed next to a file, that means the MD5 doesn't match the one from the database, which means that file was modified.

Since yum itself isn't working, it's hard to say how you could recover from this situation... Unless the rpm -V output lists something fairly obvious and fixing that seems enough, it would be hard or work intensive to download the RPMs by hand and reinstall them... If reinstalling your machine from scratch is an option, maybe you should consider doing that.

You should take extra care when installing software that doesn't come from your OS provider, particularly on a distribution such as CentOS (since the great selling point of CentOS and its upstream RHEL is their support for keeping older packages up to date on security issues, you lose that when you install software that is not managed by yum.) If you still think you should install, say, Python 2.7, try to do so under a separate directory structure such as /usr/local, so you don't disturb the Python install from the distribution under /usr.

More to the point... If you need Python 2.7, have you considered using CentOS 7 instead? CentOS 6 is pretty ancient at this point... CentOS 7 ships with Python 2.7 already, so unless you have a strong reason to stay on CentOS 6 (and I can't really imagine a good one), consider moving to the newer release.

  • 1
    Considering that CentOS 6 is at 6.10, the post say 6.6 and 6.7 came out in 2015, it’s quite possible this system has so many major issues that reinstalling it wit 7.6.1810 might be a blessing in disguise. – jsbillings Feb 22 at 23:38
  • @filbranden When I do rpm -Va 'python*' 'yum*' I get a very long list with: missing /usr/lib/python2.6/site-packages/ So it seems site-packages is missing – user210912 Feb 25 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.