No Python on RHEL/CentOS 8
! TLDR: Python is not pre-installed on RHEL/Centos 8, there is a secret Python 3
/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:
[[email protected] ~]$ python --version -bash: python: command not found [[email protected] ~]$ python2 --version -bash: python2: command not found [[email protected] ~]$ python3 --version -bash: python3: command not found
That can’t be right, lets take a closer look:
[[email protected] ~]$ find /usr/bin -name '*python*' /usr/bin/unversioned-python [[email protected] ~]$ 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
[[email protected] ~]$ which yum /usr/bin/yum [[email protected] ~]$ 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
dnf), lets check it out:
[[email protected] ~]$ /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
/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
platform-python doesn’t exist for them.
To fix this your down to nasty workarounds along the lines of:
#!/usr/local/bin/system-pythonin your integration scripts
- Have your scripts install a userland python as soon as possible so that
these scripts can shebang with
! Be aware of the support implications for using this type of workaround
Thanks to Brett Gray from MongoDB for inspiring this article.