Menu Close
Chapter 2. Installing and using Python
In RHEL 9, Python 3.9 is the default Python implementation. 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, use:
# dnf install python3
Verification steps
To verify the Python version installed on your system, use the following command:
$ python3 --version
2.2. Installing additional Python 3 packages
Packages prefixed with python3
contain modules for the default Python 3.9 version.
Procedure
To install the
Requests
module for Python, use:# dnf install python3-requests
To install the
pip
package installer from Python, use:# dnf install python3-pip
2.3. Installing additional Python 3 tools for developers
Additional Python tools for developers are distributed through the CodeReady Linux Builder repository.
This repository contains, for example, the python3-pytest
, python3-Cython
packages and many others.
The CodeReady Linux Builder repository and its content is unsupported by Red Hat.
To install packages from the repository, use the following the procedure.
Procedure
Enable the CodeReady Linux Builder repository:
# subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms
Install the
python3-pytest
package:# dnf install python3-pytest
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.
Procedure
To run the Python interpreter or related commands, use, for example:
$ python3 $ python3 -m pip --help $ python3 -m pip install package