Friday, July 4, 2014

Install cx_Oracle 5.1.3 in Ubuntu 14.04 with oracle-instantclient12.1

To be able to install cx_Oracle 5.1.3 (to manipulate an Oracle 12c database with python) in Ubuntu 14.04 with oracle-instantclient12.1 succesfully, you have to do following things:

1. Download these instant client packages from


(the packages that are in red are required)

2. Convert all rpm packages to deb using alien:

$ sudo alien -d *.rpm

3. Install all those deb packages:

$ sudo dpkg -i *.deb

4. Create the ORACLE_HOME environment variable:

Create a file: /etc/ and in the first line of the script, write (it depends on your system):


Run the commands:

$ export ORACLE_HOME=/usr/lib/oracle/12.1/client64 
$ sudo ldconfig

5. Download the cx_Oracle tar ball from pypi and extract it:

$ tar -xzvf cx_Oracle-5.1.3.tar.gz
$ cd cx_Oracle-5.1.3

6. Modify these following lines of cx_Oracle-5.1.3/, from line 123 (the red ones):

# try to determine the Oracle home
#userOracleHome = os.environ.get("ORACLE_HOME")
userOracleHome = "/usr/lib/oracle/12.1/client64"
if userOracleHome is not None:
    if not CheckOracleHome(userOracleHome):
        messageFormat = "Oracle home (%s) does not refer to an " \
                "9i, 10g, 11g or 12c installation."
        raise DistutilsSetupError(messageFormat % userOracleHome)
    for path in os.environ["PATH"].split(os.pathsep):
        if CheckOracleHome(path):
    if oracleHome is None:
        #~ raise DistutilsSetupError("cannot locate an Oracle software " \
                #~ "installation
        oracleHome = "/usr/lib/oracle/12.1/client64"

7. Build and install cx_Oracle 5.1.3:

$ python build
$ sudo python install

8. Check the installation by import the cx_Oracle module in the python clie:

$ python

> import cx_Oracle

* Updates Sep 23, 2014: you are able to install cx_Oracle simply using pip instead of installing it from source:

(myvirtualenv)$ pip install cx_Oracle