Oracle database 11g and Python cx_Oracle site-packages

Since Python and Jython  is a powerfull way to help Oracle Fusion Middleware developers, the need for database access grows. Therefore i write this installation plan to connect your Pyhton code to a Oracle 11g database using:

Instant Client Package – Basic
Instant Client Package – SQL*Plus
Instant Client Package – SDK

Follow the steps below:

  1. Download the software listed above.
  2. Extract all downloaded zips of the Oracle Instant Client to a dir which is called the ORACLE_HOME
    I used /apps/oracle/instantclient_11_2
  3. Extract the cx_Oracle dir to a tempory location, i used /apps/oracle/cx_Oracle-5.1.1
  4. Add following exports to your global Linux profile:
    </pre>
    PATH=$PATH:$HOME/bin
    ORACLE_HOME=/apps/oracle/instantclient_11_2
    PATH=$ORACLE_HOME/bin:$PATH
    PATH=$ORACLE_HOME/lib64:$PATH
    LD_LIBRARY_PATH=/apps/oracle/instantclient_11_2
    export ORACLE_HOME
    export LD_LIBRARY_PATH
    export PATH
    <pre>
  5. Go to /apps/oracle/instantclient_11_2 and generate some soft links.
    ln -s libclntsh.so.11.1 libclntsh.so
    ln -s libocci.so.11.1 libocci.so
    ln -s libocijdbc11.so libocijdbc.so
    ln -s libnnz11.so libnnz.so
    
  6. Go to the extracted cx_Oracle directory and run:
    python setup.py build
    python setup.py install
    
  7. Now start a Python shell and try:
Python 2.7.2 (default, Mar 20 2012, 03:06:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle

 If You get “missing library .so” errors:

  • Check your .bash_profile for the correct $PATH, $LD_LIBRARY_PATH and $ORACLE_HOME exports.
  • Check the permissions from the instantclient dir (/apps/oracle/instantclient_11_2)

That’s all it is to. Good luck with using your database!