If you want to connect to Oracle database you must install the oracle instant client library on your operating system. Go to oracle.com and hover download menu. You will see oracle instant client under database section and click it. Then, you should select the right operating system and architecture. I downloaded the latest versions of files which was 12.1 when I wrote this tutorial. I downloaded the following files
For 64bit
For 32bit
After downloading these rpm packages, we need to install them on debian with “alien”. If you do not have alien installed, run this as super user:
aptitude install alien
After installing alien, you need to install the rpm packages with alien. Run the following command as super user on shell within the directory you installed the rpms. Note: I am assuming these are the only rpm packages in that directory
alien -i *.rpm
After installation completed, you need to set the environment variables for oracle client, ORACLE_HOME and LD_LIBRARY_PATH. You should add them to one of your profile files under your home directory
nano ~/.bashrc
Add following lines to the file and save it
For 64bit
export ORACLE_HOME="/usr/lib/oracle/12.1/client64" export LD_LIBRARY_PATH="/usr/lib/oracle/12.1/client64/lib:$LD_LIBRARY_PATH"
For 32bit
export ORACLE_HOME="/usr/lib/oracle/12.1/client" export LD_LIBRARY_PATH="/usr/lib/oracle/12.1/client/lib:$LD_LIBRARY_PATH"
And then run
source ~/.bashrc
Since cx_Oracle
python module needs libaio
package, I install it too
aptitude install libaio1
You are ready to use the oracle instant client library.
If you need to install cx_Oracle python module, firstly, ORACLE_HOME and LD_LIBRARY_PATH environment variables must be set like I set above, and secondly you must have python-dev
and python-pip
packages installed
aptitude install python-dev python-pip
Then you can install cx_Oracle with pip
pip install cx_Oracle
Discussion