This was tested on El Capitan 10.11.4 (15E65) with python 2.7, which was installed via pyenv.
Download the sdk and client from Oracle. This guide uses 188.8.131.52.0
Unzip both of them to a local directory, we're gonna say it's /Users/ying/Applications/oracle for this guide. Create the library if it doesn't exist.
Run the following in your shell:
export ORACLE_HOME=/Users/ying/Applications/oracle export VERSION=184.108.40.206.0
This part of the guide is outdated:
I kept it around as some of the explanations are still valid.
cd into $ORACLE_HOME, and create symlinks:
ln -s libclntsh.dylib.11.1 libclntsh.dylib ln -s libocci.dylib.11.1 libocci.dylib
This part is where it differs from other guides I have seen thus far, so I'll explain a little bit what I think the reasoning is. For the other guides, usually there is a line to export DYLD_LIBRARY_PATH and LD_LIBRARY_PATH. This is supposed to be the path in which the cx_oracle libraies will try and look for libclntsh.dylib.11.1 when it runs. If you have seen this error, then you've come to the right place:
Traceback (most recent call last): File "ora_test.py", line 1, in <module> import cx_Oracle ImportError: dlopen(/Users/ying/.pyenv/versions/2.7/lib/python2.7/site-packages/cx_Oracle.so, 2): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1 Referenced from: /Users/ying/.pyenv/versions/2.7/lib/python2.7/site-packages/cx_Oracle.so Reason: image not found
However, somehow, DYLD_LIBRARY_PATH does not get picked up for me, even when setting it before the installation, right up to when the script runs. So essentially, the script cannot find the libary when it runs. fix_oralibs.rb fixes this by rewriting the dylibs to remove the /ade/b/3071542110/oracle/rdbms/lib identification name with the absolute path to the library on your machine. So, in your $ORACLE_HOME directory, get the file and run it(from here):
curl -O https://raw.githubusercontent.com/kubo/fix_oralib_osx/master/fix_oralib.rb ruby fix_oralib.rb # apply to all files in the current directory.
Workaround(as of 2016/04/22)
On El-Capitan, DYLD_LIBRARY_PATH does not get set properly. From here
Before you can use a dynamic library as a dependent library, the library and its header files must be installed on your computer. The standard locations for header files are ~/include, /usr/local/include and /usr/include. The standard locations for dynamic libraries are ~/lib, /usr/local/lib, and /usr/lib.
So, make a symlink from your $ORACLE_HOME path to ~/lib for some of the these libraries.
cd ~ mkdir lib cd lib # you may need more symlinks depending on what libraries you need to use ln -s <path-to-$ORACLE_HOME>/libclntsh.dylib.11.1 libclntsh.dylib.11.1 ln -s <path-to-$ORACLE_HOME>/libocci.dylib.11.1 <path-to-$ORACLE_HOME>/libocci.dylib ln -s <path-to-$ORACLE_HOME>/libnnz11.dylib libnnz11.dylib
pip install cx_oracle. I have tried this without the arch flags and it works on this machine.
I have not tried connection, but I have tested it with a file that simply has
import cx_module in it.
It might also be helpful to check to confirm that your python installation is 64 bit. This SO post is relevant: 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 and so is this: http://stackoverflow.com/questions/1405913/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit-mode-on-os