Download the following files from Oracle. You'll to login (it's free to register) to download the files.
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
Last step is to simply run pip
, you might have to add an arch flag:
env ARCHFLAGS="-arch $ARCH" pip install cx_Oracle
Logging creates an annoying oradiag_$USERNAME
folder in your home directory. This blog post indicates that the following steps should quell the logging.
# Make the directory
sudo mkdir -p $ORACLE_HOME/network/admin/sqlnet.ora
# Create the settings file
sudo tee -a $ORACLE_HOME/network/admin/sqlnet.ora <<EOF
DIAG_ADR_ENABLED = OFF
TRACE_LEVEL_CLIENT = OFF
TRACE_DIRECTORY_CLIENT=/dev/null
LOG_DIRECTORY_CLIENT = /dev/null
LOG_FILE_CLIENT = /dev/null
LOG_LEVEL_CLIENT = OFF
EOF
# export TNS_ADMIN so that the settings file gets loaded
echo 'export TNS_ADMIN="$ORACLE_HOME/network/admin/sqlnet.ora"' >> ~/.profile