Ol8 Pythong
Ol8 Pythong
F36403-05
October 2022
Oracle Linux 8 Installing and Managing Python,
F36403-05
1 About Python
2 Installing Python
Installing Python 2 2-1
Installing Python 3 2-2
Installing Additional Python Libraries 2-2
iii
Preface
Preface
Oracle Linux 8: 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.
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 https://www.oracle.com/corporate/accessibility/.
For information about the accessibility of the Oracle Help Center, see the Oracle
Accessibility Conformance Report at https://www.oracle.com/corporate/accessibility/
templates/t2-11535.html.
iv
Preface
products and documentation. We are also 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 8, many system utilities, tools for data analysis and
web applications rely on the presence of a Python run-time environment to function.
There are two incompatible versions of Python available for installation on Oracle Linux 8.
Python 2 is no longer maintained by the Python community and it is strongly recommended
that any existing Python 2 scripts are migrated to Python 3.
You can read more information about creating your own Python scripts at https://
www.python.org/doc/
Note:
The python command is not aliased by default in Oracle Linux 8. Specify the
Python interpreter version with the python2 and python3 commands when you
launch Python scripts.
For more information, see Installing Python.
1-1
2
Installing Python
This chapter describes how to install multiple versions of Python and switch between them on
the same Oracle Linux system.
To install Python and prerequisites, use the dnf module install command. Multiple versions
of Python can be installed and used simultaneously on the same machine, such as Python
2.7 and Python 3.6. You can specify which version you intend to use as follows:
python2 --version
python3 --version
The python command is not aliased by default in Oracle Linux 8. Specify the Python
interpreter version with the python2 and python3 commands when you launch Python scripts.
If you need to alias the python command to fix compatibility problems with existing scripts
and applications, you can set it manually. For example, to set Python 2 as the default
interpreter version:
sudo alternatives --set python /usr/bin/python2
For more information about using the python command, see the python(1) manual page.
Note:
Python 3.6 is supported for the full lifespan of Oracle Linux 8.
Application Stream packages, such as Python 2.7 and more recent versions of
Python 3, have their own major version releases and may have shorter support
lifespans. For more information, see Appendix B in Oracle Linux: Managing
Software on Oracle Linux.
Installing Python 2
To install Python 2.7 on your Oracle Linux 8 system:
sudo dnf module install python27
2-1
Chapter 2
Installing Python 3
Important:
Python 2 is no longer maintained by the Python community. Oracle strongly
recommends that you migrate your existing Python 2 scripts and applications
to Python 3.
To learn about about the 2to3 automated migration tool visit https://
docs.python.org/3/library/2to3.html. See also the porting guide at https://
portingguide.readthedocs.io/en/latest/ for more in-depth information.
Installing Python 3
To install Python 3.6 on your Oracle Linux 8 system:
sudo dnf module install python36
If you are running Oracle Linux 8.2 or later, you can optionally also install Python 3.8:
sudo dnf module install python38
If you are running Oracle Linux 8.4 or later, you can optionally also install Python 3.9:
sudo dnf module install python39
All of those Python 3 modules can be installed and used simultaneously on the same
machine, and you can specify which installation you intend to use as follows:
python3.6 --version
python3.8 --version
python3.9 --version
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
safely 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:
sudo dnf search python3-requests
For more information about installing additional Python libraries from the Oracle Linux yum
server, read Installing Additional Python Libraries.
If you cannot 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 use the pip package manager to install it from a third-party source.
To ensure that your 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.
1. Create a virtual environment named example2 for Python 2:
sudo dnf install python2-virtualenv
3. You can now activate either virtual 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
NOT_SUPPORTED:
Using the pip2 and pip3 commands outside of a virtual environment will apply
your changes system-wide, and that may impact compatibility with some
installed packages in your Oracle Linux 8 installation.
Add the --user flag to any pip install commands to ensure that dependency
packages are only available to the current user.
4. To launch compatible scripts with the third-party packages you have installed, run them
from within the same virtual environment.
To learn more about installing third-party packages inside Python virtual environments, visit
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/.
3-1