Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing python cx_oracle on Ubuntu

First of all, it just seems like doing anything with Oracle is obnoxiously painful for no good reason. It's the nature of the beast I suppose. cx_oracle is a python module that allows you to connect to an Oracle Database and issue queries, inserts, updates..usual jazz.

Linux

Step 1:

sudo apt-get install build-essential unzip python-dev libaio-dev

Step 2. Click here to download the appropriate zip files required for this. You'll need:

  • instantclient-basic-linux
  • instantclient-sdk-linux

Get the appropriate version for your system.. x86 vs 64 etc. Make sure you don't get version 12, since it's not supported by the cx_Oracle moduel yet.

Unzip the content in the same location, so you'll end up with a folder named: instantclient_11_2 (in my case) which will contain a bunch of .so and jar files.

just for ease of use I'll use $ORACLE_HOME which will basically point to the location where you unzipped your installclient folders.

export ORACLE_HOME=$(pwd)/instantclient_11_2

Step 3. create a symlink to your SO file.

cd $ORACLE_HOME
ln -s libclntsh.so.11.1   libclntsh.so  #the version number on your .so file might be different

Step 4. Update your /etc/profile or your ~/.bashrc

export ORACLE_HOME=/location/of/your/files/instantclient_11_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

Step 5: Edit /etc/ld.so.conf.d/oracle.conf

This is a new file, simple add the location of your .so files here, then update the ldpath using

sudo ldconfig

Step 6. Finaly just install cx_oracle module:

pip install cx_oracle

Mac OS X

Step 1:
install Homebower for the compilation tools

Step 2. Click here to download the appropriate zip files required for this. You'll need:

  • instantclient-basic-macosx
  • instantclient-sdk-macosx

Get the appropriate version for your system.. x32 vs x64 etc. Make sure you don't get version 12, since it's not supported by the cx_Oracle moduel yet.

Unzip the content in the same location, so you'll end up with a folder named: instantclient_11_2 (in my case) which will contain a bunch of .so and jar files.

just for ease of use I'll use $ORACLE_HOME which will basically point to the location where you unzipped your installclient folders.

export ORACLE_HOME=$(pwd)/instantclient_11_2

Step 3. create a symlink to your SO file.

cd $ORACLE_HOME
ln -s libclntsh.dylib.11.2 libclntsh.dylib  #the version number on your .so file might be different
ln -s libocci.dylib.11.2 libocci.dylib

Step 4. Update your /etc/profile or your ~/.bashrc

export ORACLE_HOME=/location/of/your/files/instantclient_11_2
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$ORACLE_HOME
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME

Step 5. Finaly just install cx_oracle module:

pip install cx_oracle
@neyer

This comment has been minimized.

Copy link

commented Sep 13, 2015

thank you so much for this!

@lyleaf

This comment has been minimized.

Copy link

commented Sep 29, 2015

Thanks very much, just have a question, what is ld.so.conf.d/oracle.conf used for? :)

@t0mst0ne

This comment has been minimized.

Copy link

commented Oct 23, 2015

Thanks very much !
Finally I can install on both OS !

@potpath

This comment has been minimized.

@latipovsharif

This comment has been minimized.

Copy link

commented Apr 28, 2016

Don't forget to download sdk for linux if will get "cx_Oracle.c:10:17: fatal error: oci.h: No such file or directory"

@raghuvital

This comment has been minimized.

Copy link

commented May 11, 2016

Thank you very much for the information.
I have a question, I have the oracle client (not the instantclient) installed on my server so Can I install this cx_oracle package and use that directly and what is the process for this?

@ulkoart

This comment has been minimized.

Copy link

commented Jun 28, 2016

Thank you very much!!!

@bawboc

This comment has been minimized.

Copy link

commented Jul 6, 2016

Collecting cx_oracle Downloading cx_Oracle-5.2.1.tar.gz (113kB) 100% |████████████████████████████████| 122kB 1.1MB/s Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-FRKMcN/cx-oracle/setup.py", line 170, in <module> raise DistutilsSetupError("cannot locate an Oracle software " \ distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation
I am still getting this error after following the instructions to the letter. Is anyone else experiencing this? How did you fix it?

@gchiappe

This comment has been minimized.

Copy link

commented Sep 5, 2016

@bawboc Hi, if you are using "sudo" to install system wide, you should add the -E flag to preserve enviroment variables, eg. "sudo -E pip install cx_Oracle", had the same problem.

@clemenbor

This comment has been minimized.

Copy link

commented Nov 7, 2016

Thank you very much for this info!!!

@TomJSmith

This comment has been minimized.

Copy link

commented Feb 27, 2017

Thanks so much for this guide! And thanks to @gchiappe for the very helpful comment.

@AdityaSuripeddi1992

This comment has been minimized.

Copy link

commented Mar 30, 2017

thank you @kimus and also @gchiappe !!

@srseven

This comment has been minimized.

Copy link

commented May 1, 2017

In /etc/ld.so.conf.d/oracle.conf, do i have to only put paths of .so files or also the file with .so.11.1 extension.

@avandesa

This comment has been minimized.

Copy link

commented May 24, 2017

This has been asked above, but "Step 5: Edit /etc/ld.so.conf.d/oracle.conf" isn't very clear. Do we put the path to the folder we extracted the files into, or the actual paths to the four .so files that are there?

@cjpit

This comment has been minimized.

Copy link

commented May 29, 2017

@avandesa simply create that file, and just put the location where you installed the instant client oracle_home dir (that directory has all the .so files in it)
so it might be something like /home/me/oracle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.