geoffwilliams@home:~$

No Python on RHEL/CentOS 8

! TLDR: Python is not pre-installed on RHEL/Centos 8, there is a secret Python 3 ! at /usr/libexec/platform-python but we are not supposed to use it. End users ! should install their own python.

Beergeek 1:48 PM No python on RHEL8 is interesting

Geoff 1:49 PM woah excuse me…

RHEL 8 has been out for a while now and Centos 8 is due to be released next week so mass-market adoption is just around the corner, but oldmate is correct, there is no Python installed by default:

[ec2-user@ip-172-31-16-152 ~]$ python --version
-bash: python: command not found
[ec2-user@ip-172-31-16-152 ~]$ python2 --version
-bash: python2: command not found
[ec2-user@ip-172-31-16-152 ~]$ python3 --version
-bash: python3: command not found

That can’t be right, lets take a closer look:

[ec2-user@ip-172-31-16-152 ~]$ find /usr/bin -name '*python*'
/usr/bin/unversioned-python
[ec2-user@ip-172-31-16-152 ~]$ unversioned-python --version
For more information about this script,
please see the manual page of the same name.
Run: man unversioned-python

If you’ve worked with RHEL for a while, then you’ll know that lots of core OS components are written in Python so it must be there somewhere unless they were all rewritten in C when no one was looking! The yum command is definitely Python, so lets see what it uses as its shebang:

[ec2-user@ip-172-31-16-152 ~]$ which yum
/usr/bin/yum
[ec2-user@ip-172-31-16-152 ~]$ head /usr/bin/yum
#!/usr/libexec/platform-python
# The dnf executable script.

This looks like a hidden version of python (and also a replacement of yum with dnf), lets check it out:

[ec2-user@ip-172-31-16-152 ~]$ /usr/libexec/platform-python --version
Python 3.6.8

That’s Python 3 alright, so what gives? RedHat have their own blog post that outlines how and why this decision was made but long story short, developers are now supposed to install python packages themselves.

For most users this isn’t a huge deal, yum install @python36 and your done. For large corporates and systems integrators things are more complicated:

  • Corporates need to ensure Python is installed in their system builds, otherwise users must beg for admin rights
  • Systems integrators are put in an awkward position. There is often the need to run scripts on first boot while building images/VMs and Python has been a natural choice over BASH because its guaranteed to be installed and makes programming easier in most cases. These kind of scripts need to run first to do things like configure network access, internal yum repositories, etc. Without a pre-installed version of Python we have a chicken-and-egg problem.

So what are us systems integrators supposed to do? The blog post makes no mention of the secret python at /usr/libexec/platform-python, however, it does exit and its Python… so you can definitely use it but would almost certainly be on your own in terms of support by doing so.

If you’ve been painted into a corner you have little option but to use the one at /usr/libexec/platform-python, which you can do by adding #!/usr/libexec/platform-python To your script. The problem with doing this is that you now need to maintain a different script for your RHEL 6/7 systems since that platform-python doesn’t exist for them.

To fix this your down to nasty workarounds along the lines of:

  1. Symlink /usr/libexec/platform-python -> /usr/local/bin/system-python
  2. Use #!/usr/local/bin/system-python in your integration scripts
  3. Have your scripts install a userland python as soon as possible so that these scripts can shebang with #!/usr/bin/env python3

! Be aware of the support implications for using this type of workaround

Thanks to Brett Gray from MongoDB for inspiring this article.

Post comment