To fix this problem, you should reinstall Python 2.7 shipped with CentOS 7.
(See below as for why you should reinstall, and how you should manage newer versions of software in a distro such as CentOS.)
Reinstalling older Python from RPM
yum is not working, you'll have to do most of it manually, by downloading the packages and reinstalling them using
For example, you can find a Python 2.7 RPM here (for CentOS 7 on x86_64):
You can fetch it using
Then, change directory to the one where you downloaded the package to, and install it using:
$ sudo rpm -Fvh --oldpackage python-*.rpm
rpm -F command,
-F for "freshen", will update packages that were already installed. Using
--oldpackage will allow you to reinstall the same version, or even install an older version, which is possible since you might have gotten package updates that are more recent than version you downloaded.)
It is possible that this is not the only package you'll need, I suggest you look at all the packages starting with
python-*, since many subpackages (
python-libs is one obvious case, but there might be others) might have been overwritten as well. You can download them from the same location (Warning: long directory listing here, it might take a while to take the whole list.)
You might need additional options such as
--nodeps, but the idea is that you manage to reinstall the package and overwrite the Python package back to the 2.7 (even if a slightly older versions, with not all the updates) from CetnOS.
To list all packages matching
python-*, you can use:
$ rpm -qa 'python-*'
You can also verify whether files from a specific package have been overwritten with:
$ rpm -V python-libs
This will list files in the package which have had at least one attribute modified. The attribute listed as
5 is the MD5 checksum of the file, that means the contents of that file have been altered.
Once you have enough packages restored, try to run
yum again, it might end up upgrading packages again.
Why reinstall Python 2.7 if I don't care about it?
An operating system such as CentOS and its upstream RHEL (Red Hat Enterprise Linux) is built for stability and reliability. Sure, that means sometimes package versions will be old, but it means everything is tested to work together.
As you've seen, Python is pretty central to CentOS/RHEL and many other packages depend on it. Well, even the package management software does. So overwriting the Python version will surely break the OS as you've seen it.
If you want a distribution that ships with latest Python, then CentOS/RHEL is not what you want. Try Fedora (closest to CentOS/RHEL but released every 6 months), Arch Linux (rolling releases) or one of the others that have releases often (every 6 months, typically) or are rolling release distros (newer packages rolling in all the time.)
How to get Python 3.7 on CentOS 7?
But if you really want/need CentOS (and there are many good reasons for it) and you want Python 3.7 (or a more recent version of about any other piece of software), look into installing it in a way that does not interfere with the version shipped by the OS, leaving that version intact.
In the specific example of Python 3.7, install it under
/opt/python-3.7 or a similar directory. Set your user's
$PATH to pick that version of Python before the system's one. Make sure you don't tweak the
/usr/bin/python symlink, instead use a
python3 one for the newer version.
The same advice can be used for most other software you would like to install in parallel with the system deployed version in a CentOS or similar Linux distribution.