Cx Oracle Python
Table of Contents
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 Platform Python included with Oracle Linux as well as new versions of Python via the Software Collection Library (SCL) and AppStream Modules. The different Python versions available and the corresponding repository and RPM names are summarized in the tables below.
Python cxOracle on macOS (Intel x86) Open all Close all. This tutorial shows you how use the Python cxOracle interface on macOS (Intel x86) to connect applications to Oracle Autonomous Database (ADB). Follow the steps below. Provision an ADB Instance. The cxOracle is designed to conform to the Python database API 2.0 specification. It also provides you with a number of additions designed specifically for the Oracle Database. The cxOracle 7.x works perfectly fine with Python version 2.7, and with versions from 3.5 to 3.7. In this section, we will only use the Python version from 3.5 to 3.7. First of all, it just seems like doing anything with Oracle is obnoxiously painful for no good reason. It's the nature of the beast I suppose. Cxoracle is a python module that allows you to connect to an Oracle Database and issue queries, inserts, updates.usual jazz. Part 2: Install cxOracle (Python’s Driver) Next you will need to install a binary of the cxOracle Python driver. This the Python side of things and interfaces Python to the actual Oracle driver (that is installed in Step 3). Issue the below command to the command line.
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 |
---|---|---|
3.8 | ol7_software_collections: rh-python38 | |
3.6 | ol7_latest: python3 | ol7_software_collections: rh-python36 |
3.5 | ol7_software_collections: rh-python35 | |
3.4 | ol7_software_collections: rh-python34 | |
2.7 | ol7_latest: python |
Installing Python
Platform Python
As Python is an integral part of the Oracle Linux operating system, each release comes with a Platform Python version. For Oracle Linux 7, the Platform Python is 2.7, and is always installed. Starting Oracle Linux 7.7, Python 3 is also available. Additional versions of Python may be installed using Software Collection Library packages.
For Oracle Linux 8 Platform Python is 3.6. Additional versions of Python may be installed using 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
Full life cycle for Python 3.6 Oracle Linux 8
Python 3.6 is supported for the full life cycle of Oracle Linux 8, during which critical security errata and select high-impact critical bug fixes will be provided.
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 for part of the Oracle Linux 8 life cycle 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 Platform Python
The Oracle Linux 7 Developer repository contains cx_Oracle RPMs for Oracle Linux 7 Platform 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 Platform 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:
For example, to install the matching cx_Oracle RPM for Python 3.6 from SCL:
$ sudo yum -y install rh-python36-python-cx_Oracle
Cx Oracle Python Install
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:
- Example Dockerfiles for Python and cx_Oracle:Oracle Linux 8, Oracle Linux 7
- Python container images on GitHub Container registry: Oracle Linux 8, Oracle Linux 7
Support
Cx_oracle Python Documentation
Oracle Linux customers receive support for Platform Python and Python packages in the Software Collection Library. Community support is available in the Python and Oracle Developer Community.
References
Cx_oracle Python
- Dev Gym: CRUD operations using cx_Oracle and Python
- Oracle Linux yum server FAQ: Configuring yum proxy