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.
The unversioned python
command points to the default Python 3.9 version.
2.1. Installing Python 3
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
To install Python 3.11, use:
# dnf install python3.11
Verification steps
-
To verify the Python version installed on your system, use the
--version
option with thepython
command specific for your required version of Python. For Python 3.9:
$ python3 --version
For Python 3.11:
$ python3.11 --version
2.2. Installing additional Python 3 packages
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.
Procedure
To install the
Requests
module for Python 3.9, use:# dnf install python3-requests
To install the
pip
package installer from Python 3.9, use:# dnf install python3-pip
To install the
pip
package installer from Python 3.11, use:# dnf install python3.11-pip
Additional resources
2.3. Installing additional Python 3 tools for developers
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-pytest
and 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
Install the
python3*-Cython
package:For Python 3.9:
# dnf install python3-Cython
For Python 3.11:
# dnf install python3.11-Cython
Additional resources
2.4. Using Python
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, install the
python3.11-pip
package.
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
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