Ol9 Python
Ol9 Python
F71308-07
June 2024
Oracle Linux 9 Installing and Managing Python,
F71308-07
1 About Python
2 Installing Python
Installing Extra Python Libraries 2-2
iii
Preface
Preface
Oracle Linux 9: Installing and Managing Python describes how to install and configure a
Python runtime environment so that you can run applications and scripting tools that require a
Python interpreter to function.
Documentation License
The content in this document is licensed under the Creative Commons Attribution–Share Alike
4.0 (CC-BY-SA) license. In accordance with CC-BY-SA, if you distribute this content or an
adaptation of it, you must provide attribution to Oracle and retain the original copyright notices.
Conventions
The following text conventions are used in this document:
Convention Meaning
boldface Boldface type indicates graphical user interface
elements associated with an action, or terms
defined in text or the glossary.
italic Italic type indicates book titles, emphasis, or
placeholder variables for which you supply
particular values.
monospace Monospace type indicates commands within a
paragraph, URLs, code in examples, text that
appears on the screen, or text that you enter.
Documentation Accessibility
For information about Oracle's commitment to accessibility, visit the Oracle Accessibility
Program website at [Link]
iv
Preface
mindful of the necessity to maintain compatibility with our customers' existing technologies and
the need to ensure continuity of service as Oracle's offerings and industry standards evolve.
Because of these technical constraints, our effort to remove insensitive terms is ongoing and
will take time and external cooperation.
v
1
About Python
Python is a high-level general purpose programming language that relies on an interpreter to
fulfill scripted functions. On Oracle Linux 9, many system utilities, tools for data analysis and
web applications rely on the presence of a Python runtime environment to function.
Python 2 is no longer maintained by the Python community; Python 2 is also not supported or
available on Oracle Linux 9. Any existing Python 2 scripts must be migrated to Python 3 or run
inside a container. For more information about running scripts inside containers, see Oracle
Linux: Podman User's Guide.
You can read more information about creating Python scripts at [Link]
Note:
Unversioned Python commands are aliased to Python 3.9 by default in Oracle Linux
9.
For more information, see Installing Python.
1-1
2
Installing Python
To install Python 3.9 on an Oracle Linux 9 system:
The python3 command points to Python 3.9 if it's installed on the system. To verify that
behavior, run the following command:
python3 --version
In Oracle Linux 9, all unversioned Python commands point to Python 3.9 and can't be
configured to run on newer Python versions by using the alternatives command.
Note:
Python 3.9 is maintained for the full lifespan of Oracle Linux 9.
Application Stream packages, such as more recent versions of Python 3, have their
own major version releases and have shorter maintenance lifespans. For more
information, see Oracle Linux: Product Life Cycle Information.
If the system is running Oracle Linux 9.2 or later, you can optionally also install Python 3.11:
If the system is running Oracle Linux 9.4 or later, you can optionally also install Python 3.12:
The python3 command is aliased to Python 3.9, so for newer versions of Python 3 you must
explicitly reference the correct binary. For example, the following command verifies that Python
3.12 is installed on the system:
python3.12 --version
2-1
Chapter 2
Installing Extra Python Libraries
To install dependency packages for specific Python versions, add the runtime version to the
package name. For example, to install the requests library for Python 3.12, run the following
command:
Dependencies that are installed in this way are available for any compatible Python
installations on the same system. In addition, any matching packages can also be removed
without also removing existing Python installations.
2-2
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:
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
[Link]
2. Create a Python virtual environment. For example, the following command creates a
Python 3 virtual environment named 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
3-1
Chapter 3
Installing Pip Libraries With Versioned Python 3
NOT_SUPPORTED:
Using the pip and pip3 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 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.
2. Create a Python virtual environment. For example, the following command creates a
Python 3.12 virtual environment named 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.12:
source example4/bin/activate
NOT_SUPPORTED:
Using the pip3.12 command outside of a Python virtual environment applies
changes system-wide.
Add the --user flag to any pip3.12 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.
3-2