Note: this post was updated on 30 january, 2019 to include simplified installation of Oracle Instant Client via Oracle Linux yum server.
cx_Oracle enables access to Oracle Database from Python and conforms with the Python database API specification. The module works with Oracle Database 11g and 12c and both Python 2.x and 3.x. We have just released the first RPM builds of cx_Oracle on the Oracle Linux yum server, including the latest cx_Oracle 7.0. You can find them in the Oracle Linux 7 (x86_64) Development (ol7_developer) and Oracle Linux 6 (x86_64) Development (ol6_developer)
This post covers the steps to install and set up cx_Oracle 7.0 with the default Python 2.7.5 on Oracle Linux 7. I used our latest Oracle Linux 7 Vagrant box
First, verify your Oracle Linux yum server configuration as we've recently made some changes in the way repository definitions are delivered. Follow the steps here to verify your setup.
Once you've verified your yum configuration, install the oracle-release-el7 and oraclelinux-developer-release-el7 release packages to set up yum repository access for Oracle Instant Client and cx_Oracle.
$ sudo yum -y install oracle-release-el7 oraclelinux-developer-release-el7
Note that case matters here. The RPM is called python-cx_Oracle
sudo yum -y install python-cx_Oracle ... Running transaction Installing : oracle-instantclient18.3-basic-184.108.40.206.0-2.x86_64 1/2 Installing : python-cx_Oracle-7.0-1.0.1.el7.x86_64 2/2 Verifying : python-cx_Oracle-7.0-1.0.1.el7.x86_64 1/2 Verifying : oracle-instantclient18.3-basic-220.127.116.11.0-2.x86_64 2/2 Installed: python-cx_Oracle.x86_64 0:7.0-1.0.1.el7 Dependency Installed: oracle-instantclient18.3-basic.x86_64 0:18.104.22.168.0-2 Complete!
cx_Oracle depends on Oracle Instant Client. During OpenWorld 2018 we released Oracle Instant Client 18.3 RPMs on Oracle Linux yum server in the ol7_oracle_instantclient and ol6_oracle_instantclient repositories, making installation a breeze. Assuming you have enabled the repository for Oracle Instant Client appropriate for your Oracle Linux release, it is installed as a dependency. Older releases of Oracle Instant Client are available on OTN.
Oracle Instant Client was installed as a dependency of cx_Oracle in the previous step. Before you can make use of Oracle Instant Client, set the runtime link path so that cx_Oracle can find the libraries it needs to connect to Oracle Database.
$ sudo sh -c "echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf" $ sudo ldconfig
$ python Python 2.7.5 (default, Nov 1 2018, 03:12:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36.0.1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle >>> db = cx_Oracle.connect("firstname.lastname@example.org/orclpdb1") >>> db.version '22.214.171.124.0' >>>
These cx_Oracle RPMs offer Python-on-Oracle developers a quick and straightforward way to get started. Give it a try and let us know what you think in the comments or in the Python and Oracle Developer Community
In this next post I go into more detail about what the different cx_Oracle RPMs are for and I show how to install our cx_Oracle RPM on Oracle Linux 6 to connect Python 3.5 to Oracle Database. See this page information about Python on Oracle Linux