X

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

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

Note: When I first wrote this post, we had just released cx_Oracle packages using a different naming scheme. In this revision dated 7 Feb. 2018 I use the new, correct naming conventions. The following RPMs will no longer be updated:

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

 

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 Python to Oracle Database 12c.

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 themed repositories for Oracle Linux 6, you'll notice a number of different versions of cx_Oracle. The following command was run with the ol6_developer and ol6_software_collections repositories enabled. 

$ yum list *python*cx_Oracle*
Loaded plugins: security
Available Packages
python-cx_Oracle.x86_64                 6.0.2-2.el6 ol6_developer           
python-cx_Oracle-12c.x86_64             5.3-2.el6   ol6_developer           
rh-python35-python-cx_Oracle.x86_64     6.0.2-1.el6 ol6_software_colle...
rh-python35-python-cx_Oracle-12c.x86_64 5.3-2.el6   ol6_software_col...

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 and is called simply python-cx_Oracle. The other, named rh-python35-python-cx_Oracle is for Python 3.5 as included in the Software Collection Library (SCL) and is therefore in the ol6_software_collections repo. Note also that, unlike version 6.0, 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 -y install yum-utils
$ sudo yum-config-manager --enable ol6_software_collections
$ sudo yum -y 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
# Set the runtime link path using ldconfig
$ sudo yum -y install ./oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
$ sudo sh -c "echo /usr/lib/oracle/12.2/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig

Install cx_Oracle 6.0 for Python 3.5 from the Software Collection Library

# Install cx_Oracle
$ sudo yum -y install rh-python35-python-cx_Oracle

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
'12.2.0.1.0'

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

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