Skip to content

Instantly share code, notes, and snippets.

@ryanhiebert
Forked from thom-nic/cx_oracle_instructions.md
Last active January 30, 2022 15:42
Show Gist options
  • Save ryanhiebert/9354154 to your computer and use it in GitHub Desktop.
Save ryanhiebert/9354154 to your computer and use it in GitHub Desktop.

Install cx_Oracle for Python on OS X

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

See: http://stackoverflow.com/questions/8169946/cant-get-cx-oracle-to-work-with-python-version-2-7-mac-os-10-7-2-lion-mis/8452731#8452731

Disable Oracle Instant Client Logging

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment