1

I have upgraded my system (CentOS 7) to Python 3.7 and it seems that has broken a ton of things. In particular, I can't perform a yum upgrade ...

[myuser@server ~]$ sudo yum upgrade
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.us-midwest-1.nexcess.net
 * epel: mirror.layeronline.com
 * extras: mirror.us-midwest-1.nexcess.net
 * updates: mirror.us-midwest-1.nexcess.net
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax


Exiting on user cancel

Is there any way I can heal the pain here?

7

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

Since yum is not working, you'll have to do most of it manually, by downloading the packages and reinstalling them using rpm directly.

For example, you can find a Python 2.7 RPM here (for CentOS 7 on x86_64):

http://mirror.centos.org/centos/7/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm

You can fetch it using wget or curl.

Then, change directory to the one where you downloaded the package to, and install it using:

$ sudo rpm -Fvh --oldpackage python-*.rpm

(The 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 --force and --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 /usr/local, /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.

  • 3
    EPEL has add-on versions of python. I know they definitely have 3.4, maybe 3.6. Unsure about 3.7. – Aaron D. Marasco Jun 12 at 22:54
  • Hi, When I ran "sudo rpm -ivh --oldpackage python-.rpm" I got the error, "error: File not found by glob: python-.rpm" – Dave Jun 12 at 23:57
  • @Dave did you download the RPM file from that URL? The glob is simply referring to that file... – filbranden Jun 13 at 0:12
  • 3
    The whole point of EPEL is to provide newer packages that can be safely installed on RHEL and CentOS, and the Python 3 packages are no exception; they install alongside the Python 2 packages without breaking them. EPEL provides Python 3.6.8 currently. – Stephen Kitt Jun 13 at 4:32
  • 1
    Another safe approach is to use software collections for CentOS; SCL currently provides Python 3.5.1. – Stephen Kitt Jun 13 at 4:35

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.