Skip to content

Instantly share code, notes, and snippets.

@broqdev
Forked from thom-nic/cx_oracle_instructions.md
Last active April 9, 2016 00:04
Show Gist options
  • Select an option

  • Save broqdev/72342b22ff8ae2f250730c9244aa2484 to your computer and use it in GitHub Desktop.

Select an option

Save broqdev/72342b22ff8ae2f250730c9244aa2484 to your computer and use it in GitHub Desktop.
Installing CX Oracle for Python & Mac OS X. Instructions exist around the web, but they seem to be piecemeal and incomplete.

Installing cx_Oracle (x86_64) for Mac OSX (tested on El Capitan 10.11.4)

Assume you've got homebrew installed.

Assume python is installed through

brew install python --universial

Install instant client

Download the following files from Oracle

  • instantclient-basic-macos.x64-11.2.0.4.0.zip
  • instantclient-sdk-macos.x64-11.2.0.4.0.zip

Install

export ORACLE_HOME=/usr/lib/share/oracle
mkdir -p $ORACLE_HOME

cd $ORACLE_HOME
tar -xzf instantclient-basic-macos.x64-11.2.0.4.0.zip
tar -xzf instantclient-sdk-macos.x64-11.2.0.4.0.zip

ln -s libclntsh.dylib.11.1 libclntsh.dylib
ln -s libocci.dylib.11.1 libocci.dylib

curl -O https://raw.githubusercontent.com/kubo/fix_oralib_osx/master/fix_oralib.rb
ruby fix_oralib.rb --absolute-path

Install cx_Oracle

Download source code of cx_Oracle (https://sourceforge.net/projects/cx-oracle/files/5.1.2/)

  • cx_Oracle-5.1.2.tar.gz

Install

export DYLD_LIBRARY_PATH=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
export OCI_LIB_DIR=$ORACLE_HOME
export OCI_INC_DIR=$ORACLE_HOME/sdk/include

mkdir ~/cx
cd ~/cx
tar -xzf cx_Oracle-5.1.2.tar.gz

python setup.py build install

If there is some permission problem during "python setup.py", don't use "sudo" but try to use "chown" to get permission.

Fix cx_Oracle.DatabaseError: ORA-21561: OID generation failed

echo "127.0.0.1 $(hostname)" | sudo tee -a /etc/hosts

Test

Run python and try to import cx_Oracle

import cx_Oracle
con = cx_Oracle.connect ('username/password@hostname:port/sid')
print(con.version)
con.close()

You may get some UserWarning but that's fine. If there is some error then something is wrong.

Refrences

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment