Posts Tagged ‘help cx_Oracle’

Installing cx_Oracle

October 25, 2013 4 comments

I needed to use python with oracle.
Before the installation, this is what I get.

>>> import cx_Oracle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cx_Oracle

Follow the steps below.
Download version 11 of Oracle instantclient (as the cx_Oracle 5.1.2 in this article will not work with an oracle version past 11g. Both x86 and x64 will work.)

Installination Steps.
1. Download oracle instant client from (You need to register on the site first.)
Get the following files

Extract them all into the same folder.

2. Make sure you have the following packages installed.
(I use synaptic to install these as I am on debian 6)


3. Set ORACLE_HOME variable in your .profile file.

$ cd ~
$ vim .profile

# Add the following to the end of the file. Change the path to point to the directory where you unzipped the files you downloaded in step 1 above.

export ORACLE_HOME="/usr/local/oracle/instantclient_11_2"

4. Create a soft link to NB. Do this for a different terminal so that you can read the new changes in .profile. (Or source .profile YMMV.)

$ cd ~
$ ln -s

5. As root, update ldconfig

$ su 
root> cd /etc/

Add the following line to oracle.conf. Create the file if it does not exist.

root> vim oracle.conf

Once done run the following command.

root> ldconfig

6. Download cx_Oracle from sourceforge
Please note that version 5.1.2 does not as yet support the latest version of instantclient. So make sure that you download version 11 not 12. You can tell which versions are supported by reading and looking for filesToCheck. Change directory to where you extracted the files to.
As root.

root> cd cx_Oracle-5.1.2/
root> python build
root> python install

Update (2014.Dec.06)
If you get the following error when you try “python build”
Traceback (most recent call last):
File "", line 132, in
raise DistutilsSetupError("cannot locate an Oracle software " \
distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation

It is because it is not able to find $ORACLE_HOME
Switch to another terminal

$source .profile
$cd cx_Oracle-5.1.2/

Then as root try to build and install again.

7. Check your install.

$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> print cx_Oracle.version

Update (2014.Nov.25)

Followed the same instructions to install on Linux x64.

$ python
Python 2.7.8 (default, Sep  9 2014, 22:08:43) 
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> print cx_Oracle.version
Categories: oracle, python Tags: ,