Python for Oracle Linux

All about developing with Python on Oracle Linux

  • Home > 
  • Python for Oracle Linux

About Python on Oracle Linux

There are several ways to get started with Python development on Oracle Linux. Oracle Linux yum server offers updates for system Python included with Oracle Linux as well as new versions of Python via the Software Collection Library (SCL) and EPEL (Oracle Linux 7 only). The different Python versions available and the corresponding repository and RPM names are summarized in the tables below.


Oracle Linux 8  
Python Version AppStream Module
3.9 python39
3.8 python38
3.6 python36
2.7 python27

Oracle Linux 7 Repository: RPM name
Python Version Base Oracle Linux Software Collection Library EPEL
3.8
ol7_software_collections: rh-python38
3.6 ol7_latest: python3 ol7_software_collections: rh-python36 ol7_developer_EPEL: python36
3.5

ol7_software_collections: rh-python35

3.4

ol7_software_collections: rh-python34 ol7_developer_EPEL: python34
2.7 ol7_latest: python




Installing Python

System Python

Python is an integral part of the Oracle Linux operating system. Oracle Linux 7 has Python 2.7 already installed and includes Python 3 starting Oracle Linux 7.7. Python is not installed by default on Oracle Linux 8. Instead, different versions of Python can be installed via AppStream Modules.

About Support for Python 2

The Python Software Foundation, the community organization behind Python, has announced that the Python 2 series has reached end-of-life on January 1, 2020 with release 2.7. Because Oracle Linux is an enterprise Linux distribution, support decisions for components in the operating system are made independently from those made in the upstream community. Therefore, Python 2 remains supported in Oracle Linux as outlined below.

Continued support for Python 2 in Oracle Linux 7

Python 2 remains supported in Oracle Linux 7. As such, critical security errata and select high-impact critical bug fixes will be provided while Oracle Linux 7 is covered under Oracle Linux Premier support as detailed in the Lifetime Support Policy

Continued support for Python 2 in Oracle Linux 8

Python 2 is delivered in Oracle Linux 8 via Application Streams and may optionally be installed. Python 2 is supported in Oracle Linux 8 and critical security errata and select high-impact critical bug fixes will be provided according to this Oracle Linux 8 Application Stream Life Cycle.

Installing Python 3 from the Oracle Linux 7 Latest Repository

Oracle Linux 7.7 and newer include Python 3.

To install Python 3 from the Oracle Linux 7 latest repository:

$ sudo yum install -y python3


Note that python3-devel is in the ol7_optional_latest repository. To install python3-devel:

$ sudo yum install -y --enablerepo ol7_optional_latest python3-devel


Installing Python From the Software Collection Library

The Software Collection Library (SCL) is intended for development environments which require access to the latest features of software components such as Perl, PHP, or Python. For these environments, it's important to minimize the disruption of system processes that rely on the versions of these components. The SCL enables you to install and use several versions of the same software on a system, simultaneously, and without disruption.

To install Python 3.8 from the SCL on Oracle Linux 7, install oracle-softwarecollection-release-el7 and then install scl-utils and rh-python38:

$ sudo yum install -y oracle-softwarecollection-release-el7
$ sudo yum -y install scl-utils rh-python38


To enable and use Python 3.8 from the SCL:

$ scl enable rh-python38 bash
$ python

Installing Python on Oracle Linux 8 via AppStream Modules

Oracle Linux 8 introduces the concept of Application Streams, where multiple versions of user-space components can be delivered and updated more frequently than the core operating system packages in RPM format or groups of related RPMs called Modules. Oracle Linux 8 offers several independently updated versions of Python via seperate modules.

To list available Python modules:

$ sudo dnf module list | grep python


To install the Python 3.9 module and run Python 3.9:

$ sudo dnf module install python39
$ python3.9


To use pip with Python 3.9 for installing additional Python packages:

$ sudo dnf install python39-pip
$ python3.9 -m pip install <package name>

To create a virtual environment using venv:

$ python3.9 -m venv py39env
$ source py39env/bin/activate


cx_Oracle: Connecting Python to Oracle Database

cx_Oracle is a module that enables access to Oracle Database and conforms to the Python database API specification. For more details, see the cx_Oracle documentation

About Oracle Instant Client

cx_Oracle depends on Oracle Instant Client. Starting with Oracle Instant Client 21c, yum/dnf configuration files are delivered via the packages oracle-instantclient-release-el8 and oracle-instantclient-release-el7, respectively. Oracle Instant Client packages up to release 19c are in the ol7_oracle_instantclient and ol8_oracle_instantclient repositories, configured with release packages oracle-release-el7 and oracle-release-el8. Assuming you have enabled the repository for Oracle Instant Client appropriate for your Oracle Linux release, it will be installed as a dependency. More details about Oracle Instant Client on this yum server..

Installing cx_Oracle for Python 3

To install cx_Oracle for Python 3 on Oracle Linux 7:

$ sudo yum -y install oraclelinux-developer-release-el7
$ sudo yum -y install oracle-instantclient-release-el7
$ sudo yum -y install python36-cx_Oracle


To install cx_Oracle for Python 3 on Oracle Linux 8:

$ sudo yum -y install oraclelinux-developer-release-el8
$ sudo dnf -y install oracle-instantclient-release-el8
$ sudo dnf -y install python36-cx_Oracle


Installing cx_Oracle for System Python

The Oracle Linux 7 Developer repository contains cx_Oracle RPMs for Oracle Linux 7 system Python 2.7 up to version cx_Oracle 7. cx_Oracle 7 packages are built with Oracle Instant Client 18.3. To install cx_Oracle for System Python on Oracle Linux 7, enable the ol7_developer and the ol7_oracle_instantclient repo and run:

$ sudo yum -y install oraclelinux-developer-release-el7
$ sudo yum -y install oracle-release-el7
$ sudo yum -y install python-cx_Oracle

Installing cx_Oracle for Python from the Software Collection Library (SCL)

cx_Oracle RPM built to work with SCL Python versions are named according to the following format:

rh-python<version>-python-cx_Oracle

For example, to install the matching cx_Oracle RPM for Python 3.6 from SCL:

$ sudo yum -y install rh-python36-python-cx_Oracle

Important: Configuring Your Environment for Oracle Instant Client

Finally, for Oracle Instant Client releases before 19.x, you must set up the environment so that cx_Oracle can find the necessary libraries. For example, for Oracle Instant Client release 18.3:

$ sudo sh -c "echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig

Python in Containers

To run Python applications —including the cx_Oracle package— in containers see the resources below:

Support

Oracle Linux customers receive support for System Python and Python packages in the Software Collection Library. Community support is available in the Python and Oracle Developer Community.


References

Contact Us

software.hardware.complete
Subscribe | Careers | Contact Us | Legal Notices | Terms of Use | Your Privacy Rights