Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Installing CX Oracle for Python & Mac OS X. Instructions exist around the web, but they seem to be piecemeal and incomplete.

Installing cx_Oracle for Python/ Mac OSX

Portions taken from (in case that link ever dies.)

Assume you've got homebrew installed.

Download the following files from Oracle

Create a directory /usr/lib/share/oracle

export ORACLE_HOME=/usr/lib/share/oracle
export VERSION=
export ARCH=x86_64

mkdir -p $ORACLE_HOME

Unpack both files to that directory:

tar -xzf instantclient-basic-$
tar -xzf instantclient-sdk-$

ln -s libclntsh.dylib.11.2 libclntsh.dylib
ln -s libocci.dylib.11.2 libocci.dylib


(Note I did not have to do anything with as suggested in the original utexas instructions.)

If you're using Pip:

Last step is to simply run pip, you might have to add an arch flag:

env ARCHFLAGS="-arch $ARCH" pip install cx_Oracle

If you're building from source:

Download cx_Oracle-version.tar.gz from Sourceforge

export CX_ORA_VERSION=5.1.2
tar -xzf cx_Oracle-$CX_ORA_VERSION.tar.gz
cd cx_Oracle-$CX_ORA_VERSION

env ARCHFLAGS="-arch $ARCH" python build
sudo python install


Some folks have recommended compiling for 32-bit (i386) instead, although I'm not sure why. 64 bit seems to work for me so YMMV.


# compile cx_Oracle for 32-bit (requires downloading 32-bit instantclient sources)
ARCHFLAGS="-arch i386" pip install cx_Oracle

# then make your virtualenv python 32-bit only:
virtualenv .
mv bin/python python.fat
lipo python.fat -remove x86_64 -output bin/python


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.