Red Hat Enterprise Linux 9 (RHEL 9) and its compatible distributions have moved on from Python 2. If you're still relying on Python 2 for testing or legacy applications, you might be wondering how to get it running. The good news is that you can use Docker to run Python 2 on RHEL 9.
The Problem with Python 2 on RHEL 9
Python 2 has been deprecated for a while now, and RHEL 9 has followed suit by removing it from its repositories. This means you can't simply install Python 2 using the package manager. While this is a step in the right direction for security and modernization, it can cause issues for those who still need to run Python 2 applications.
Using Docker to Run Python 2
One way to run Python 2 on RHEL 9 is to use a Docker image. Docker allows you to create a containerized environment that can run a specific version of Python, independent of the host system's configuration. You can use Podman, a compatible alternative to Docker, to achieve this.
Pulling the Python 2 Docker Image
To get started, you'll need to pull the Python 2 Docker image. You can do this using the following command:
This command downloads the Python 2.7 image from Docker Hub.
Running Python 2 from the Docker Image
Once the image is downloaded, you can run Python 2 using the following command:
Let's break down what this command does:
podman runstarts a new container from the specified image.
-rmremoves the container when it exits, keeping your system tidy.
v "$PWD":/scripts:zmounts the current working directory ($PWD) to/scriptsinside the container, allowing you to access your scripts. The:zflag is used to relabel the volume with the correct SELinux context.
w /scriptssets the working directory inside the container to/scripts.
docker.io/python:2.7specifies the image to use.
python gen_random_mac.pyruns thegen_random_mac.pyscript using Python 2.7.
Conclusion
While Python 2 is no longer available on RHEL 9 by default, you can still run it using a Docker image. By following the steps outlined above, you can create a containerized environment that runs Python 2, allowing you to test and run legacy applications. This solution provides a convenient workaround for those who still rely on Python 2.
