Este contenido no está disponible en el idioma seleccionado.
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 Copiar enlaceEnlace copiado en el portapapeles!
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.9To install Python 3.11, use:
# dnf install python3.11To install Python 3.12, use:
# dnf install python3.12
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.9 --versionFor Python 3.11:
$ python3.11 --versionFor Python 3.12:
$ python3.12 --version
2.2. Installing additional Python 3 packages Copiar enlaceEnlace copiado en el portapapeles!
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.9-requestsTo install the
pippackage installer from Python 3.9, use:# dnf install python3.9-pipTo install the
pippackage installer from Python 3.11, use:# dnf install python3.11-pipTo install the
pippackage installer from Python 3.12, use:# dnf install python3.12-pip
2.3. Installing additional Python 3 tools for developers Copiar enlaceEnlace copiado en el portapapeles!
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-rpmsInstall the
python3*-Cythonpackage:For Python 3.9:
# dnf install python3.9-CythonFor Python 3.11:
# dnf install python3.11-CythonFor Python 3.12:
# dnf install python3.12-Cython
2.4. Using Python Copiar enlaceEnlace copiado en el portapapeles!
Examples show how to run the Python interpreter and Python-related commands. The examples cover Python 3.9, 3.11, and 3.12, including starting the interpreter, using virtual environments, and installing packages with pip.
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.
Installing Python packages with pip as 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 using pip at the system level. To avoid these issues, use pip within a virtual environment or install packages as a non-root user with the --user option.
Procedure
To run the Python 3.9 interpreter or related commands, use, for example:
$ python3.9 $ python3.9 -m venv --help $ python3.9 -m pip install package $ pip3 install packageTo 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 packageTo 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