Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 2. Installing and using Python
In RHEL 9, Python 3.9 is the default Python implementation. Since RHEL 9.2, Python 3.11 is available as the python3.11 package suite, and since RHEL 9.4, Python 3.12 as the python3.12 package suite.
The unversioned python command points to the default Python 3.9 version.
2.1. Installing Python 3 Copier lienLien copié sur presse-papiers!
The default Python implementation is usually installed by default. To install it manually, use the following procedure.
Procedure
To install Python 3.9, use:
dnf install python3
# dnf install python3Copy to Clipboard Copied! Toggle word wrap Toggle overflow To install Python 3.11, use:
dnf install python3.11
# dnf install python3.11Copy to Clipboard Copied! Toggle word wrap Toggle overflow To install Python 3.12, use:
dnf install python3.12
# dnf install python3.12Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
-
To verify the Python version installed on your system, use the
--versionoption with thepythoncommand specific for your required version of Python. For Python 3.9:
python3 --version
$ python3 --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.11:
python3.11 --version
$ python3.11 --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.12:
python3.12 --version
$ python3.12 --versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.2. Installing additional Python 3 packages Copier lienLien copié sur presse-papiers!
Packages prefixed with python3- contain add-on modules for the default Python 3.9 version. Packages prefixed with python3.11- contain add-on modules for Python 3.11. Packages prefixed with python3.12- contain add-on modules for Python 3.12.
Procedure
To install the
Requestsmodule for Python 3.9, use:dnf install python3-requests
# dnf install python3-requestsCopy to Clipboard Copied! Toggle word wrap Toggle overflow To install the
pippackage installer from Python 3.9, use:dnf install python3-pip
# dnf install python3-pipCopy to Clipboard Copied! Toggle word wrap Toggle overflow To install the
pippackage installer from Python 3.11, use:dnf install python3.11-pip
# dnf install python3.11-pipCopy to Clipboard Copied! Toggle word wrap Toggle overflow To install the
pippackage installer from Python 3.12, use:dnf install python3.12-pip
# dnf install python3.12-pipCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3. Installing additional Python 3 tools for developers Copier lienLien copié sur presse-papiers!
Additional Python tools for developers are distributed mostly through the CodeReady Linux Builder (CRB) repository.
The python3-pytest package and its dependencies are available in the AppStream repository.
The CRB repository contains, for example, the following packages:
-
python3*-idle -
python3*-debug -
python3*-Cython -
python3.11-pytestand its dependencies -
python3.12-pytestand its dependencies.
The content in the CodeReady Linux Builder repository is unsupported by Red Hat.
Not all upstream Python-related packages are available in RHEL.
To install packages from the CRB repository, use the following procedure.
Procedure
Enable the CodeReady Linux Builder repository:
subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms
# subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpmsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
python3*-Cythonpackage:For Python 3.9:
dnf install python3-Cython
# dnf install python3-CythonCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.11:
dnf install python3.11-Cython
# dnf install python3.11-CythonCopy to Clipboard Copied! Toggle word wrap Toggle overflow For Python 3.12:
dnf install python3.12-Cython
# dnf install python3.12-CythonCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4. Using Python Copier lienLien copié sur presse-papiers!
The following procedure contains examples of running the Python interpreter or Python-related commands.
Prerequisites
- Ensure that Python is installed.
If you want to download and install third-party applications for Python 3.11 or Python 3.12, install the
python3.11-piporpython3.12-pippackage.WarningInstalling Python packages with
pipas the root user places files in system locations. This can override RHEL libraries and might cause system instability or conflicts with supported packages. Red Hat does not support software installed by usingpipat the system level. To avoid these issues, usepipwithin a virtual environment or install packages as a non-root user with the--useroption.
Procedure
To run the Python 3.9 interpreter or related commands, use, for example:
python3 python3 -m venv --help python3 -m pip install package pip3 install package
$ python3 $ python3 -m venv --help $ python3 -m pip install package $ pip3 install packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the Python 3.11 interpreter or related commands, use, for example:
python3.11 python3.11 -m venv --help python3.11 -m pip install package pip3.11 install package
$ python3.11 $ python3.11 -m venv --help $ python3.11 -m pip install package $ pip3.11 install packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow To run the Python 3.12 interpreter or related commands, use, for example:
python3.12 python3.12 -m venv --help python3.12 -m pip install package pip3.12 install package
$ python3.12 $ python3.12 -m venv --help $ python3.12 -m pip install package $ pip3.12 install packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow