Portions taken from http://www.cs.utexas.edu/~mitra/csSpring2011/cs327/cx_mac.html (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=11.2.0.3.0
export ARCH=x86_64
mkdir -p $ORACLE_HOME
Unpack both files to that directory:
cd $ORACLE_HOME
tar -xzf instantclient-basic-$VERSION-macosx-x64.zip
tar -xzf instantclient-sdk-$VERSION-macosx-x64.zip
ln -s libclntsh.dylib.11.2 libclntsh.dylib
ln -s libocci.dylib.11.2 libocci.dylib
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
(Note I did not have to do anything with ottclasses.zip
as suggested in the original utexas instructions.)
Last step is to simply run pip
, you might have to add an arch flag:
env ARCHFLAGS="-arch $ARCH" pip install cx_Oracle
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 setup.py build
sudo python setup.py 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.
Basically:
# 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
This worked for me (building from source) until the last step.
python setup.py build finished (with the following warnings:
57 warnings generated.
creating build/lib.macosx-10.9-intel-2.7-11g
cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.9-intel-2.7-11g/cx_Oracle.o -L/Users/205893/Oracle/instantclient_11_2 -lclntsh -o build/lib.macosx-10.9-intel-2.7-11g/cx_Oracle.so -shared-libgcc
ld: warning: ignoring file /Users/205893/Oracle/instantclient_11_2/libclntsh.dylib, file was built for x86_64 which is not the architecture being linked (i386): /Users/205893/Oracle/instantclient_11_2/libclntsh.dylib
d
However when I ran the setup.py install I got the following familiar error:
daniel-gendler-7103:cx_Oracle-5.1.2 205893$ sudo python setup.py install
Traceback (most recent call last):
File "setup.py", line 132, in
raise DistutilsSetupError("cannot locate an Oracle software "
distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation
I'm not a particularly sophisticated Mac user and would appreciate any insight. Thanks.