Skip to content

Instantly share code, notes, and snippets.

@mcescalante
Last active November 13, 2017 20:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mcescalante/50f1663825fea582953c187f83c8b92d to your computer and use it in GitHub Desktop.
Save mcescalante/50f1663825fea582953c187f83c8b92d to your computer and use it in GitHub Desktop.
cx_Oracle installation instructions/notes for macOS or Linux

cx_Oracle Installation Instructions

I've had to put cx_Oracle (python Oracle database connector) on macOS and Linux, and both processes were similar but poorly documented on Oracle's website.

These instructions were written and tested using the client 12.1. The instructions for any 12.x are the same, but you may need to change 12_1 to 12_2 in commands if you are using version 12.2, etc.

Instructions

  1. Download 64 bit (easy to download 32 by mistake) basic + sdk instantclient from Oracle website (Note: you need an account, I used throwaway email)

  2. mkdir /usr/local/lib/oracle (we should not use /usr/lib in macOS due to SIP)

    • Note: you may choose any directory you wish, such as /opt/oracle on Linux but be sure to replace the directories in any instructions below with your choice.
  3. Unzip + move the downloaded files directly to /usr/local/lib/oracle/instantclient_12_1

    • tar -xvf instantclient-basic-macos.x64-11.2.0.4.0.zip -C /usr/local/lib/oracle
    • tar -xvf instantclient-sdk-macos.x64-11.2.0.4.0.zip -C /usr/local/lib/oracle
  4. Link libraries to non-version specific names (cd /usr/local/lib/oracle/instantclient_12_1 if you haven't)

    • ln -s libclntsh.dylib.12.1 libclntsh.dylib
    • ln -s libocci.dylib.12.1 libocci.dylib
  5. Add environment variables to PATH (add to .profile, .bash_profile, .zshrc etc.)

    • export ORACLE_HOME=/usr/local/lib/oracle/instantclient_12_1
    • export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
    • export PATH=$ORACLE_HOME:$PATH
  6. Install cx_Oracle with pip

    • pip install cx_Oracle
  7. Test that it's working properly

    • python
    • import cx_Oracle

    The import should execute without an error, and you're off and running.

@youeee
Copy link

youeee commented Mar 20, 2017

Hi Thanks for the instructions.

Everything works fine until step 7. Error I get is

>>> 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

@Gwildor
Copy link

Gwildor commented Jul 21, 2017

Thanks for your updated version of the guide. However, there is a step missing at step 4. Before creating the symbolic links, you need to move the files after unpacking. This is simply done by running mv instantclient_11_2/* .

@mcescalante
Copy link
Author

mcescalante commented Nov 13, 2017

Gwildor is right, previously, some of the instructions were incorrect and had assumed that the files inside the folder instantclient_12_1 or whatever were moved directly into /usr/local/lib/oracle. I have updated the instructions to the latest instantclient and adjusted those commands so that no file moving is needed (i.e. instantclient_12_1 is included in commands).

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