# Python ## Overview ```{note} This guide only covers RHEL8/9 and newer. Also we will __not__ cover how to use Python 2 any more. ``` There are several versions of Python(3) available from RedHat. This guide shows how one can install specific/multiple versions and how to configure the default Python of a system. The use of Python environments like [`venv`](https://docs.python.org/3/library/venv.html) or [Conda](https://docs.conda.io) is recommended if a single user needs one or multiple specific Python environments. But this is not part of this guide. ## Platform Python vs Default Python As many system tools are written in Python each RHEL8/9 system comes with a so called Platform Python. This is a _fixed_ Python version than cannot be modified and usually is also not available via the commandline. Beside that, on each system you can install multiple Python versions. One of this Python version can then be set as the Default Python. This means that this Python version is called if you call `python` and/or `python3` on the commandline/script. To explicitly call a specific Python version always specify the full version as follows: `python`, e.g. `python3.12`. The same applies to the `pip` command! ### Using the Platform Python For system tools, that should run consistently on all systems you may decide to use the "Platform Python" instead of the Default Python. For doing so you need to set the shebang of your script to ```bash #!/usr/libexec/platform-python ``` ## Python Versions On __RHEL8__ the Platform (and usual Default) Python version is __3.6__. As the time of writing following Python versions are additinally available: _3.8_, _3.9_, _3.11_, _3.12_ . On __RHEL9__ the Platform (and usual Default) Python version is __3.9__. As the time of writing following Python versions are additinally available: _3.11_, _3.12_ ## Configuration Following hiera keys can be used to configure Python on a system. ### Installing and Setting a Default Python To install a default Python you can use: ```yaml python::default_version: '3.11' ``` This will make sure that that this Python version is installed on the system and that this Python version is available via the `python` and `python3` command. The same applies for `pip` and `pip3`. ### Installing Additional Python Versions To install additional Python versions on the system you can use: ```yaml python::install_versions: ['3.6', '3.12'] ``` This will take care that the necessary packages are installed on the system. These versions are then available by calling the version specific Python command `python