X

News, tips, partners, and perspectives for the Oracle Linux operating system and upstream Linux kernel work

Installing cx_Oracle and Oracle Instant Client via Oracle Linux Yum Server

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 
 

1. Confirm Yum Configuration

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

2. Enable ol7_developer and ol7_oracle_instantclient Repositories

$ sudo yum -y install yum-utils
$ sudo yum-config-manager --enable ol7_developer ol7_oracle_instantclient

3. Install cx_Oracle RPM

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-18.3.0.0.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.3.0.0.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.3.0.0.0-2                                                                              

Complete!

4. Add the Oracle Instant Client to the Runtime Link Path

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

5. Test connection to Oracle Database

$ 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("scott/tiger@10.0.1.127/orclpdb1")
>>> db.version
'12.2.0.1.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

Read on...

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

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services