Install cx-Oracle on Mavericks

cx-Oracle is a Python Oracle DB connection package, ealier today I met some trouble installing on my macbook running Mavericks, after hacking I found the means to install it correctly:

  1. Download instantclient-basic-macos.x64-11.2.0.4.0.zip and instantclient-sdk-macos.x64-11.2.0.4.0.zip from http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html.
  2. Download the cx-Oracle source code from http://cx-oracle.sourceforge.net.
  1. Create a new directory to place the Oracle client files.

    mkdir -p /opt/oracle/
  2. Move instantclient-basic-macos.x64-11.2.0.4.0.zip and instantclient-sdk-macos.x64-11.2.0.4.0.zip into the folder /opt/oracle/.
  3. cd into /opt/oracle, unzip the two package.

    cd /opt/oracle/ unzip instantclient-basic-macos.x64-11.2.0.4.0.zip unzip instantclient-sdk-macos.x64-11.2.0.4.0.zip

  4. cd into instantclient_11_2/sdk, unzip the package ottclasses.zip.

    cd instantclient112/sdk unzip ottclasses.zip

  5. Copy some files.

    cd /opt/oracle/
    cp -R ./sdk/* .
    cp -R ./sdk/include/* .
  6. Make some soft links so that cx-Oracle can correctly recognize the Oracle client.

    ln -s libclntsh.dylib.11.1 libclntsh.dylib
    ln -s libocci.dylib.11.1 libocci.dylib
  7. Edit ~/.bash_profile, add these lines.

    export ORACLE_HOME=/opt/opracle/instantclient_11_2
    export DYLD_LIBRARY_PATH=$ORACLE_HOME
    export LD_LIBRARY_PATH=$ORACLE_HOME

    then source it.

    source ~/.bash_profile
  8. Now we have installed the Oracle client, it's cx-Oracle's turn.

    tar -xzvf cxOracle-5.1.2.tar.gz cd cxOracle-5.1.2.tar.gz sudo python setup.py build sudo python setup.py install

  9. Now we can check it out whether cx-Oracle is successfully installed.

    >>> import cx_Oracle
    # If this works without a problem, then cx_Oracle is successfully installed.

If you have any questions, plz let me know in the comments.

About the author

Hey, I'm Peixuan, a software engineer. I write posts about things I learned.

dinever