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

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.9
  • To install Python 3.11, use:

    # dnf install python3.11
  • To install Python 3.12, use:

    # dnf install python3.12

Verification

  • To verify the Python version installed on your system, use the --version option with the python command specific for your required version of Python.
  • For Python 3.9:

    $ python3.9 --version
  • For Python 3.11:

    $ python3.11 --version
  • For Python 3.12:

    $ python3.12 --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. Packages prefixed with python3.12- contain add-on modules for Python 3.12.

Procedure

  • To install the Requests module for Python 3.9, use:

    # dnf install python3.9-requests
  • To install the pip package installer from Python 3.9, use:

    # dnf install python3.9-pip
  • To install the pip package installer from Python 3.11, use:

    # dnf install python3.11-pip
  • To install the pip package installer from Python 3.12, use:

    # dnf install python3.12-pip

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
  • python3.12-pytest and its dependencies.
Important

The content in the CodeReady Linux Builder repository is unsupported by Red Hat.

Note

Not all upstream Python-related packages are available in RHEL.

To install packages from the CRB repository, use the following procedure.

Procedure

  1. Enable the CodeReady Linux Builder repository:

    # subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms
  2. Install the python3*-Cython package:

    • For Python 3.9:

      # dnf install python3.9-Cython
    • For Python 3.11:

      # dnf install python3.11-Cython
    • For Python 3.12:

      # dnf install python3.12-Cython

2.4. Using Python

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-pip or python3.12-pip package.
Warning

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 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
  • 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
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2026 Red Hat
Retour au début