Tuesday, December 29, 2009

Django and Oracle support

To get work Django and Oracle client in Ubuntu:

Download cx_Oracle (choose for your system), Oracle InstantClient and Sql*Plus (in this page you can choose your OS and download the packages (in my case are oracle-instantclient11.2-basic-11.2.0.0.2-1.x86_64.rpm and oracle-instantclient11.2-sqlplus-11.2.0.0.2-1.x86_64.rpm).

Move the files into one directory for simplicity and run

alien -k *.rpm
dpkg -i *.deb
to convert all the downloaded packages to ubuntu deb-format and install them.

Then make symlink to lib, otherwise module won't be found by Django

cd /usr/lib/python2.6
ln -s site-packages/cx_Oracle.so

To avoid

Traceback (most recent call last):
  File "", line 1, in 
ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory
add to ~/.bashrc (or /etc/bash.bashrc to system-wide apply)
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/11.2/client64/lib

If you see the message
Traceback (most recent call last):
  File "", line 1, in 
ImportError: libaio.so.1: cannot open shared object file: No such file or directory
run
sudo apt-get install -y libaio1

P.S. If you choose more modern (or older) version of Oracle IntstantClient you have to create symlinks for necessary version, e.g. you see the following error:

Traceback (most recent call last):
  File "", line 1, in 
ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory
but in /usr/lib/oracle/11.2/client64/lib directory exists libclntsh.so.11.1. Just make it symbolic link with
ln -s libclntsh.so.11.1 libclntsh.so.10.1

1 comment:

  1. I found it is possible to avoid the need to kludge up your LD_LIBRARY_PATH:

    Make a file /etc/ld.so.conf.d/oracle-instantclient11.1-basic.conf

    containing

    /lib
    /usr/lib/oracle/11.2/client64/lib

    then sudo ldconfig

    ReplyDelete

Note: Only a member of this blog may post a comment.