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.12, run the following command:
sudo dnf search python3.12-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
venv
Python module.
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 3
-
Install base packages for the
pip3
command:sudo dnf install python3-pip python3-setuptools python3-pip-wheel
-
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
-
You can now activate the
example3
environment and begin installing third-party dependencies. For example, to install a newer version of therequests
library for Python 3:source example3/bin/activate
python3 -m pip install --user requests
Attention:
Using the
pip
andpip3
commands outside of a Python virtual environment applies changes system-wide, and that can impact compatibility with some installed packages in an Oracle Linux 9 installation.Add the
--user
flag to anypip3 install
commands to ensure that dependency packages are only available to the current user. -
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.12, follow these instructions:
-
Install base packages for the
pip3.12
command:sudo dnf install python3.12-pip python3.12-setuptools python3.12-wheel
-
Create a Python virtual environment. For example, the following command creates a Python 3.12 virtual environment named
example4
:python3.12 -m venv --system-site-packages example4
-
You can now activate the
example4
environment and begin installing third-party dependencies. For example, to install a newer version of therequests
library for Python 3.12:source example4/bin/activate
python3.12 -m pip install --user requests
Attention:
Using the
pip3.12
command outside of a Python virtual environment applies changes system-wide.Add the
--user
flag to anypip3.12 install
commands to ensure that dependency packages are only available to the current user. -
To run compatible scripts with the third-party packages that have been installed, run them from within the same Python virtual environment.