Skip to content

Instantly share code, notes, and snippets.

@rmoff rmoff/foo.md
Last active Mar 28, 2019

Embed
What would you like to do?
cx_Oracle install on MacOS
  1. Download Instant Client:
  • instantclient-basic-macos.x64-11.2.0.4.0.zip
  • instantclient-sdk-macos.x64-11.2.0.4.0.zip
  • instantclient-sqlplus-macos.x64-11.2.0.4.0.zip
  1. Unzip and move to /opt

  2. Create symlink

     $ cd /opt/instantclient_11_2/
     $ ln -s libclntsh.dylib.11.1 libclntsh.dylib
    
  3. [ This step might not be needed ]

    Copy files:

     sudo cp /opt/instantclient_11_2/sdk/include/*.h /usr/include/
     sudo cp /opt/instantclient_11_2/*.dylib /usr/lib
     sudo cp /opt/instantclient_11_2/sqlplus /usr/bin
    
  4. Run pip install. If it needs root permission, su to root first. Make sure you do this rather than sudo because you need to set the environment variable in the correct shell

     export ORACLE_HOME=/opt/instantclient_11_2
     pip install cx_Oracle
    
  5. Test:

     Python 2.7.6 (default, Sep  9 2014, 15:04:36)
     [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
     Type "help", "copyright", "credits" or "license" for more information.
     >>> import cx_Oracle
     >>> conn_str = u'USER/PASSWORD@host.foo.com:1521/orcl'
     >>> conn = cx_Oracle.connect(conn_str)
     >>> c = conn.cursor()
     >>> c.execute(u'select sysdate from dual')
     <cx_Oracle.Cursor on <cx_Oracle.Connection to USER/PASSWORD@host.foo.com:1521/orcl>>
     >>> for row in c:
     ...     print row
     ...
     (datetime.datetime(2015, 2, 19, 15, 56, 5),)
     >>>
    

If you get this:

Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
  Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so
  Reason: image not found

Then make sure you've set DYLD_LIBRARY_PATH correctly:

export DYLD_LIBRARY_PATH=/opt/instantclient_11_2/
@haveaguess

This comment has been minimized.

Copy link

commented Sep 22, 2015

Thanks

@ganeshchand

This comment has been minimized.

Copy link

commented Jan 27, 2016

I have export DYLD_LIBRARY_PATH=/opt/instantclient_11_2/ setup in my ~/.bash_profile and I am still getting the error:
ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so
Reason: image not found
My Environment: OS X El Capitan - 10.11.2
Python: 2.7
Oracle Instant Client - 64-bit: instantclient-sdk-macos.x64-11.2.0.4.0.zip and instantclient-basic-macos.x64-11.2.0.4.0.zip

I can connect to the Oracle database using sqlplus without any issue.

@shaungehring

This comment has been minimized.

Copy link

commented Feb 25, 2016

I am having the fact same issue as ganeshchand

@brightredchilli

This comment has been minimized.

Copy link

commented Apr 21, 2016

Hi guys, I ran into the same issue here and fixed it by running the script made here: https://github.com/kubo/fix_oralib_osx.
This writeup has more information: https://gist.github.com/brightredchilli/10a7962491b06a9bbbb9353aa510f942

@kyleian

This comment has been minimized.

Copy link

commented Aug 29, 2017

Cheers, confirmed it was DYLD_LIBRARY_PATH was incorrect and absolved the error after redirecting to the installation path.

@Ellis-Joshua

This comment has been minimized.

Copy link

commented Feb 23, 2018

I think I botched my installation some how, however I figured out a work around.

when I was done following these instructions and even other tutorials I found online I kept getting this error:

conn = cx_Oracle.connect(conn_str)
Traceback (most recent call last):
File "", line 1, in
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "dlopen(libclntsh.dylib, 1): image not found". See https://oracle.github.io/odpi/doc/installation.html#macos for help

After some playing around with it I found that as long as I was in $DYLD_LIBRARY_PATH I could run cx_oracle just fine however that's unpractical. I did some more playing around and I found that if I create a $DYLD_LIBRARY_PATH/lib directory and add a link to $DYLD_LIBRARY_PATH/libclntsh.dylib in that directory was able to get it working.

Long story short I think some of these files need to be moved into /lib however for now I don't know which ones. What I did to get it working:

sudo mkdir $ORACLE_HOME/lib
sudo ln -s $DYLD_LIBRARY_PATH/libclntsh.dylib $ORACLE_HOME/lib/

@oscdmdz

This comment has been minimized.

Copy link

commented Mar 15, 2018

his worked for me, it has to be in the lib folder

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

@patrickmch

This comment has been minimized.

Copy link

commented Sep 20, 2018

Thank you!

@GautamSingh1002

This comment has been minimized.

Copy link

commented Sep 26, 2018

Thanks, every step made sense. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.