how to set up cx_Oracle on ubuntu [solved]

I tried installing oracle client to use it with sqlalchemy and ended up with a nasty error message:

distutils.errors.DistutilsSetupError: cannot locate Oracle include files

To setup cx_Oracle so that it can be imported from python, proceed as follow:

  1. install libaio.so.1 by running:
    sudo apt-get install libaio1
  2. download instant client appropriate for your platform from oracle website: http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
    SDK and ODBC packages must be downloaded too.
    note: on my side i downloaded:
    oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
    oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
    oracle-instantclient12.1-odbc-12.1.0.2.0-1.x86_64.rpm
  3. convert into .deb package:
    sudo alien -d *instantcl*.rpm

    note: you may need to install alien (sudo apt-get install alien) if not already done

  4. install created package:
    sudo dpkg -i *instantcl*.deb
  5. create file sudo vi /etc/ld.so.conf.d/oracle.conf with content pointing to oracle default installation directory:
    /usr/lib/oracle/12.1/client64
  6. create environments variable:
    export ORACLE_HOME=/usr/lib/oracle/12.1/client64
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib

    note: make changes permanent by adding declaration into ~/.bashrc

  7. run
    sudo ldconfig
  8. install python library:
    python -m pip install cx_oracle

    note: above syntax is for python 3.5 and above, otherwise run “pip install cx_oracle”, you may also need to install pip via “sudo apt-get install python3-pip”

  9. Log in a python console and ensure “import cx_Oracle” is successful!

cx_oracle_ubuntu

Done!

sources

Post a Comment

Your email is never published nor shared. You're allow to say what you want...