Skip to content

Instantly share code, notes, and snippets.

@EnesKorukcu
Forked from rmoff/foo.md
Created July 18, 2019 13:30
Show Gist options
  • Save EnesKorukcu/1869fef8805a9f5667fc33349171795c to your computer and use it in GitHub Desktop.
Save EnesKorukcu/1869fef8805a9f5667fc33349171795c to your computer and use it in GitHub Desktop.
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/
@EnesKorukcu
Copy link
Author

EnesKorukcu commented Jul 18, 2019

In macOS mojave, it's not possible to copy under /usr/lib.
Instead i copied *. dylib files under /usr/local/lib.
And it works!

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