Install cx_Oracle on mac osx El Capitan (10.11.5)

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:

  • Pyhton
  • 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:

  • instantclient-basic-macos.x64-12.1.0.2.0.zip
  • instantclient-sdk-macos.x64-12.1.0.2.0.zip

(You can also try with the 32bit version, but this did work for me.)

I placed the files under:

 /Applications/cx_Oracle/

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-12.1.0.2.0.zip
christian.sisti@cisco: unzip instantclient-sdk-macos.x64-12.1.0.2.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"

Throubleshoot

 If the above command does not work you may have to fix the rpath. Just execute:
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

Should I learn first design patterns or object oriented principles?

This is a question I faced while chatting with a Junior Java Developer recently. I think it is an interesting question, especially because it seems the two things could be put on the same level at first glance.

You find below my answer, hoping it is clear enough and that may help someone else clarifying this.

Think at the two words. What a pattern is in this context? A solution to an already seen problem. You shouldn’t look for or force patterns in your code but the fact you know them may save you some time/pain.

If you realise that for the problem you are facing you need an object that can be instantiated one and only one time, you may spend time for finding how to implement such mechanism or you may remind that this is a Singleton pattern. So you already have the solution. Patterns are all about not reinventing the wheel.

On the other side principles are the fundamental bricks of your coding paradigm. You may not know patterns and still write decent code. Pattern may change or became obsolete. For example in Spring all the beans are singleton by default. If you always work with such framework you may never see a Singleton implementation.

But you MUST know, understand and master principles.