Skip to content

Instantly share code, notes, and snippets.

Last active January 18, 2019 03:34
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?


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

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=

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 "", line 1, in <module>
    import cx_Oracle
ImportError: dlopen(/Users/ying/.pyenv/versions/2.7/lib/python2.7/site-packages/, 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/
  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
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

Finally, run 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: and so is this:

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