Chapter 37. Introduction to Python
Python is a high-level programming language that supports multiple programming paradigms, such as object-oriented, imperative, functional, and procedural paradigms. Python has dynamic semantics and can be used for general-purpose programming.
With Red Hat Enterprise Linux, many packages that are installed on the system, such as packages providing system tools, tools for data analysis, or web applications, are written in Python. To use these packages, you must have the
python* packages installed.
37.1. Python versions
Two incompatible versions of Python are widely used, Python 2.x and Python 3.x. RHEL 8 provides the following versions of Python.
Table 37.1. Python versions in RHEL 8
|Version||Package to install||Command examples||Available since||Life cycle|
| || || |
full RHEL 8
| || || |
| || || |
| || || |
For details about the length of support, see Red Hat Enterprise Linux Life Cycle and Red Hat Enterprise Linux 8 Application Streams Life Cycle.
Each of the Python versions is distributed in a separate module and by design you can install multiple modules in parallel on the same system.
python39 modules do not include the same bindings to system tools (RPM, DNF, SELinux, and others) that are provided for the
python36 module. Therefore, use
python36 in instances where the greatest compatibility with the base operating system or binary compatibility is necessary. In unique instances where system bindings are necessary together with later versions of various Python modules, use the
python36 module in combination with third-party upstream Python modules installed through
pip into Python’s
Always specify the version of Python when installing it, invoking it, or otherwise interacting with it. For example, use
python3 instead of
python in package and command names. All Python-related commands should also include the version, for example,
python command (
/usr/bin/python) is not available by default in RHEL 8. You can configure it using the
alternatives command; for instructions, see Configuring the unversioned Python. Any manual changes to
/usr/bin/python, except changes made using the
alternatives command, might be overwritten upon an update.
As a system administrator, use Python 3 for the following reasons:
- Python 3 represents the main development direction of the Python project.
- Support for Python 2 in the upstream community ended in 2020.
- Popular Python libraries are discontinuing Python 2 support in upstream.
Python 2 in Red Hat Enterprise Linux 8 will have a shorter life cycle and aims to facilitate a smoother transition to
Python 3for customers.
For developers, Python 3 has the following advantages over Python 2:
- Python 3 enables you to write expressive, maintainable, and correct code more easily.
- Code written in Python 3 will have greater longevity.
Python 3 has new features, including
asyncio, f-strings, advanced unpacking, keyword-only arguments, and chained exceptions.
However, legacy software might require
/usr/bin/python to be configured to Python 2. For this reason, no default
python package is distributed with Red Hat Enterprise Linux 8, and you can choose between using Python 2 and 3 as
/usr/bin/python, as described in Configuring the unversioned Python.
System tools in Red Hat Enterprise Linux 8 use Python version 3.6 provided by the internal
platform-python package. Red Hat advises customers to use the
python36 package instead.