I struggled quite a bit to make cx_Oracle work for my Python installation.
I checked various resources online and everything was quite messy. So I decided to contribute by adding some more mess around. In order to make it work you need:
- Oracle Instant Client
It seems easy but actually making it work Oracle Instant Client on mac is a little bit tricky. Let’s start from the beginning:
This is the version of Python I am using:
christian.sisti@cisco: python --version Python 2.7.10
1. Get Oracle Instant Client
Go here and download the most recent version of the client. For me it was:
(You can also try with the 32bit version, but this did work for me.)
I placed the files under:
Then you have to unzip the them and copy the sdk into the correct folder:
christian.sisti@cisco: cd /Applications/cx_Oracle christian.sisti@cisco: unzip instantclient-basic-macos.x64-184.108.40.206.0.zip christian.sisti@cisco: unzip instantclient-sdk-macos.x64-220.127.116.11.0.zip
Note that the unzip command should already copy the sdk folder of the sdk package on the instaclient basic folder. If that doesn’t work for you, you have to do it manually.
2. Setup ENV variables
These are the environment variables I’ve added to my bash profile. Remember to restart the terminal in order to make it pick them up.
christian.sisti@cisco: emacs ~/.bash_profile # Oracle Client for Python: cx_Oracle export ORACLE_HOME='/Applications/cx_Oracle/instantclient_12_1' export DYLD_LIBRARY_PATH=$ORACLE_HOME export LD_LIBRARY_PATH=$ORACLE_HOME export CLASSPATH=$CLASSPATH:$ORACLE_HOME export FORCE_RPATH=TRUE export PATH=$ORACLE_HOME:$PATH
3. Setup symlinks
There is a couple of symlink that need to be configured:
ln -s "$ORACLE_HOME"/libclntsh.dylib.* "$ORACLE_HOME"/libclntsh.dylib ln -s "$ORACLE_HOME"/libocci.dylib.* "$ORACLE_HOME"/libocci.dylib
4. Install cx_Oracle
christian.sisti@cisco: sudo pip install cx_Oracle==5.2.1
5. Test installation
If everything was find then the following command should’t return any output:
christian.sisti@cisco: python -c "import cx_Oracle"
install_name_tool -add_rpath $ORACLE_HOME ~/.python-eggs/cx_Oracle-5.2.1-py2.7-macosx-10.11-intel.egg-tmp/cx_Oracle.so