Note: this post was updated on 6 November, 2018 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, make sure you have the most recent Oracle Linux yum server repo file by grabbing it from the source:
$ sudo mv /etc/yum.repos.d/public-yum-ol7.repo /etc/yum.repos.d/public-yum-ol7.repo.bak $ sudo wget -O /etc/yum.repos.d/public-yum-ol7.repo http://yum.oracle.com/public-yum-ol7.repo
$ sudo yum -y install yum-utils $ sudo yum-config-manager --enable ol7_developer ol7_oracle_instantclient
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-220.127.116.11.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-18.104.22.168.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:22.214.171.124.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 '126.96.36.199.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