0% found this document useful (0 votes)
1 views10 pages

Ol9 Python

The document provides guidance on installing and managing Python on Oracle Linux 9, including the installation of Python 3.9, 3.11, and 3.12, as well as extra libraries and third-party packages using pip. It emphasizes the importance of using virtual environments for package management to avoid compatibility issues. Additionally, it highlights the discontinuation of Python 2 and the need to migrate existing scripts to Python 3.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views10 pages

Ol9 Python

The document provides guidance on installing and managing Python on Oracle Linux 9, including the installation of Python 3.9, 3.11, and 3.12, as well as extra libraries and third-party packages using pip. It emphasizes the importance of using virtual environments for package management to avoid compatibility issues. Additionally, it highlights the discontinuation of Python 2 and the need to migrate existing scripts to Python 3.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Oracle Linux 9

Installing and Managing Python

F71308-07
June 2024
Oracle Linux 9 Installing and Managing Python,

F71308-07

Copyright © 2022, 2024, Oracle and/or its affiliates.


Contents
Preface
Documentation License iv
Conventions iv
Documentation Accessibility iv
Access to Oracle Support for Accessibility iv
Diversity and Inclusion iv

1 About Python

2 Installing Python
Installing Extra Python Libraries 2-2

3 Installing Third-Party Packages


Installing Pip Libraries With Python 3 3-1
Installing Pip Libraries With Versioned Python 3 3-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]

Access to Oracle Support for Accessibility


Oracle customers that have purchased support have access to electronic support through My
Oracle Support. For information, visit [Link]
[Link]#support-tab.

Diversity and Inclusion


Oracle is fully committed to diversity and inclusion. Oracle respects and values having a
diverse workforce that increases thought leadership and innovation. As part of our initiative to
build a more inclusive culture that positively impacts our employees, customers, and partners,
we are working to remove insensitive terms from our products and documentation. We are also

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:

sudo dnf install python3

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.

To optionally enable the unversioned python command, install the python-unversioned-


command package:

sudo dnf install /usr/bin/python

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:

sudo dnf install python3.11

If the system is running Oracle Linux 9.4 or later, you can optionally also install Python 3.12:

sudo dnf install python3.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

Installing Extra Python Libraries


You can also install extra dependencies from the Oracle Linux yum server. For example, to
install the requests library for the default runtime version of Python 3, you would install the
python3-requests package:

sudo dnf install python3-requests

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:

sudo dnf install python3.12-requests

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:

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
[Link]

Installing Pip Libraries With Python 3


1. Install base packages for the pip3 command:

sudo dnf install python3-pip python3-setuptools python3-pip-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

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.

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:
1. Install base packages for the pip3.12 command:

sudo dnf install python3.12-pip python3.12-setuptools python3.12-wheel

2. 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

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

python3.12 -m pip install --user requests

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

You might also like