- Download both the "Instant Client Package - Basic Lite" and "Instant Client Package - SDK" ZIP files from the Oracle Instant Client download page (taking note of the version of Oracle you are connecting to)
- Unzip both the files, they will create a directory correponding to the Oracle version, instantclient_11_2 for example
- Change to the instantclient directory created in the previous step and:
- Create symbolic links to the version specific files:
- libclntsh.so -> libclntsh.so.11.1
- libocci.so -> libocci.so.11.1
- Create a lib directory (mkdir lib)
- Move lib* to the lib directory (mv lib* lib)
- Move header files from ./sdk/include to . (mv ./sdk/include/*.h .)
- Optionally move the instantclient directory to another location
- Sudo to root (sudo -s) and build the module:
- Install the python-dev package (apt-get install python-dev)
- Export environment variables:
- export ORACLE_HOME="path/to/instantclient"
- export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$ORACLE_HOME/lib"
- Install the cx_oracle module using pip (pip install cx_oracle)
- Hopefully get a "Successfully installed cx-oracle" message
- Exit the root shell (Ctrl-D)
- Add the ORACLE_HOME and LD_LIBRARY_PATH environment variables to your profile (or just manually export them)
- Launch python and test:
>>> dsn = cx_Oracle.makedsn('host', port, 'sid')
>>> connection = cx_Oracle.connect('user','password',dsn)
>>> cursor = connection.cursor()
>>> results = cursor.execute("select id from table where ROWNUM <= 10")
>>> cursor.fetchall()
[(705,), (718,), (719,), (721,), (725,), (726,), (727,), (737,), (748,), (769,)]
>>> cursor.close()
>>> connection.close()