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.
-
Download 64 bit (easy to download 32 by mistake) basic + sdk instantclient from Oracle website (Note: you need an account, I used throwaway email)
-
mkdir /usr/local/lib/oracle(we should not use/usr/libin macOS due to SIP)- Note: you may choose any directory you wish, such as
/opt/oracleon Linux but be sure to replace the directories in any instructions below with your choice.
- Note: you may choose any directory you wish, such as
-
Unzip + move the downloaded files directly to
/usr/local/lib/oracle/instantclient_12_1tar -xvf instantclient-basic-macos.x64-11.2.0.4.0.zip -C /usr/local/lib/oracletar -xvf instantclient-sdk-macos.x64-11.2.0.4.0.zip -C /usr/local/lib/oracle
-
Link libraries to non-version specific names (
cd /usr/local/lib/oracle/instantclient_12_1if you haven't)ln -s libclntsh.dylib.12.1 libclntsh.dylibln -s libocci.dylib.12.1 libocci.dylib
-
Add environment variables to PATH (add to .profile, .bash_profile, .zshrc etc.)
export ORACLE_HOME=/usr/local/lib/oracle/instantclient_12_1export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATHexport PATH=$ORACLE_HOME:$PATH
-
Install cx_Oracle with pip
pip install cx_Oracle
-
Test that it's working properly
pythonimport cx_Oracle
The import should execute without an error, and you're off and running.
Gwildor is right, previously, some of the instructions were incorrect and had assumed that the files inside the folder
instantclient_12_1or 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_1is included in commands).