3 Installing Third-Party Packages

Before installing a third-party package, verify if you can install the Python library you need from the Oracle Linux yum server. For example, to check if the requests library has been provided for Python 3.11, run the following command:

sudo dnf search python3.11-requests

For more information about installing extra Python libraries from the Oracle Linux yum server, read Installing Extra Python Libraries.

If you can't find a particular dependency on the Oracle Linux yum server, or if the script that you need to run requires a newer version of the dependency than the installed package already provides, you can optionally use the pip package manager to install it from a third-party source.

To ensure that the system remains supported, for each project you can install and run third-party packages in an isolated virtual environment created with the virtualenv and venv Python modules.

To learn more about installing third-party packages inside Python virtual environments, visit https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/.

Installing Pip Libraries With Python 2

  1. Install base packages for the pip2 command and virtual environments:

    sudo dnf install python-pip python-setuptools python-wheel python-virtualenv
  2. Create a Python virtual environment. For example, the following command creates a Python 2 virtual environment named example2:

    python2 -m virtualenv --system-site-packages example2
  3. You can now activate the example2 environment and begin installing third-party dependencies. For example, to install a newer version of the requests library for Python 2:

    source example2/bin/activate
    python2 -m pip install --user requests

    Attention:

    Using the pip or pip2 commands outside of a Python virtual environment applies changes system-wide, and that can impact compatibility with some installed packages in an Oracle Linux 8 installation.

    Add the --user flag to any pip2 install commands to ensure that dependency packages are only available to the current user.

  4. To run compatible scripts with the third-party packages that have been installed, run them from within the same Python virtual environment.

Installing Pip Libraries With Python 3

  1. Install base packages for the pip3 command:

    sudo dnf install python3-pip python3-setuptools python3-wheel
  2. Create a Python virtual environment. For example, the following command creates a Python 3 virtual environment named example3:

    python3 -m venv --system-site-packages example3
  3. You can now activate the example3 environment and begin installing third-party dependencies. For example, to install a newer version of the requests library for Python 3:

    source example3/bin/activate
    python3 -m pip install --user requests

    Attention:

    Using the pip3 command outside of a Python virtual environment applies changes system-wide, and that can impact compatibility with some installed packages in an Oracle Linux 8 installation.

    Add the --user flag to any pip3 install commands to ensure that dependency packages are only available to the current user.

  4. To run compatible scripts with the third-party packages that have been installed, run them from within the same Python virtual environment.

Installing Pip Libraries With Versioned Python 3

You can also install third-party dependencies for newer releases of Python 3 by using versioned pip commands. For example, to install Pip libraries for Python 3.11, follow these instructions:

  1. Install base packages for the pip3.11 command:

    sudo dnf install python3.11-pip python3.11-setuptools python3.11-wheel
  2. Create a Python virtual environment. For example, the following command creates a Python 3.11 virtual environment named example4:

    python3.11 -m venv --system-site-packages example4
  3. You can now activate the example4 environment and begin installing third-party dependencies. For example, to install a newer version of the requests library for Python 3.11:

    source example4/bin/activate
    python3.11 -m pip install --user requests

    Attention:

    Using the pip3.11 command outside of a Python virtual environment applies changes system-wide.

    Add the --user flag to any pip3.11 install commands to ensure that dependency packages are only available to the current user.

  4. To run compatible scripts with the third-party packages that have been installed, run them from within the same Python virtual environment.