Portions taken from http://www.cs.utexas.edu/~mitra/csSpring2011/cs327/cx_mac.html & https://gist.github.com/thom-nic/6011715
Download the following files from Oracle
instantclient-basic-macos.x64-12.1.0.2.0.zip instantclient-sdk-macos.x64-12.1.0.2.0.zip
Create a directory /usr/local/lib/share/oracle
export ORACLE_HOME=/usr/local/lib/share/oracle
export VERSION=12.1.0.2.0
export ARCH=x86_64
mkdir -p $ORACLE_HOME
Copy Instant Client Basic & SDK to /usr/local/lib/share/oracle
cp instantclient-basic-macos.x64-$VERSION.zip $ORACLE_HOME
cp instantclient-sdk-macos.x64-$VERSION.zip $ORACLE_HOME
Unpack both files to that directory:
cd $ORACLE_HOME
tar -xzf instantclient-basic-macos.x64-$VERSION.zip
tar -xzf instantclient-sdk-macos.x64-$VERSION.zip
Create Symbolic links in the instant client folder in /user/local/lib/share/oracle
cd instantclient_12_1
ln -s libclntsh.dylib.12.1 libclntsh.dylib
ln -s libocci.dylib.12.1 libocci.dylib
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
now you can get rid of the zip files you downloaded as they aren't needed anymore
cd /usr/local/lib/share/oracle
rm instantclient-basic-macos.x64-$VERSION.zip
rm instantclient-sdk-macos.x64-$VERSION.zip
move all the files & folders outside of /instantclient_12_1 to the parent directory /usr/local/lib/share/oracle
mv -v $ORACLE_HOME/instantclient_12_1/* /$ORACLE_HOME/
rm -rf instantclient_12_1/
You should be able to install cx_Oracle now.
##Troubleshooting
If you're experiencing cx_Oracle.DatabaseError: ORA-21561: OID generation failed
Get the hostname of your computer by typing in terminal
hostname
copy this value and add it to your /etc/hosts
file with your favorite text editor(i'm using vi in this case)
vi /etc/hosts
on the line that has 127.0.0.1 localhost
at the end of it put a space and enter your hostname given to you earlier. below, you see MYMACSNAME, replace that portion with your hostname you received
127.0.0.1 localhost MYMACSNAME