Oracle Linux | Friday, September 29, 2017

Using cx_Oracle With Software Collection Library and What Those Different Versions Are For

In a previous post, I explained that we published cx_Oracle RPMs on Oracle Linux yum server and described the steps to install cx_Oracle 6.0 with the Oracle Instant Client and connect to a database from Python.

Today I'll describe how to use Oracle Linux 6 with Python 3.5 from the Sofware Collection Library and connect to a database using our new cx_Oracle 6.0 RPM.

About the different cx_Oracle versions on Oracle Linux yum server

In our Developer repository for Oracle Linux 6, you'll notice a number of different versions of cx_Oracle.  

$ yum list cx_Oracle*

Loaded plugins: security
Available Packages
cx_Oracle-12c-py26.x86_64                5.3-1.el6          ol6_developer
cx_Oracle-12c-py35-scl.x86_64          5.3-1.el6        ol6_developer
cx_Oracle-py26.x86_64                     6.0.2-1.el6   ol6_developer
cx_Oracle-py35-scl.x86_64              6.0.2-1.el6           ol6_developer   

The ones that include version 5.3 are —you guessed it— cx_Oracle 5.3. At the time of this writing, there are two different cx_Oracle 5.3 RPMs.  Both are for Oracle Database 12c but for different versions of Python. One is for use with the default Python 2.6 that ships with Oracle Linux 6. The other is for Python 3.5 as included in the Software Collection Library (SCL). Note the -scl in the RPM name. Note also that version 5.3 of cx_Oracle is built for a specific release of Oracle Database (12c in this case).

Based on a new abstraction layer called ODPI-C, one of the benefits of cx_Oracle 6.0 is that the same module now supports Oracle Client 11.2, 12.1 and 12.2. No need for separate builds and no need to include the database release in the name.  

These are the steps to install and enable Python 3.5 from the software collection library, install the Oracle Instant Client and the appropriate cx_Oracle 6.0

Enable the Software Collections repository and install and Python 3.5

# Enable ol6_software_collections repository
# install scl-utils and Python 3.5 from SCL

$ sudo yum install yum-utils
$ sudo yum-config-manager --enable ol6_software_collections
$ sudo yum install scl-utils rh-python35

Download and install Oracle Instant Client

Download and install the Instant Client RPM for Oracle Linux x86-64.  Look for "Instant Client Package - Basic".

# Install instant client rpm via yum to resolve any dependencies
$ sudo yum install ./oracle-instantclient12.2-basic-
$ export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib/:$LD_LIBRARY_PATH

Install cx_Oracle 6.0 for Python 3.5 from the Software Collection Library

# Install cx_Oracle
$ sudo yum install cx_Oracle-py35-scl

Enable Python 3.5 and connect to the database

# Enable Python 3.5 from the SCL and run python
# connect to a database
$ scl enable rh-python35 bash
$ python
Python 3.5.1 (default, Dec 19 2016, 02:12:44) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> db = cx_Oracle.connect("scott/tiger@dmyhost/pdb")
>>> db.version

These new 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

Join the discussion

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

Visit the Oracle Blog


Contact Us


Integrated Cloud Applications & Platform Services