Wednesday, August 21, 2013

How to install ox_Oracle in RHEL 64 bit and get it working

Ok this sucked... but it is done now and hopefully this helps one person somewhere, please comment if it does.

So this is the version of RHEL I am using when I call uname -or
2.6.32-358.el6.x86_64 GNU/Linux

I didn't know what version of Oracle was running and so rather than asking the DBA I just ran this SQL statement in my developer tool: "Select * from v$version;"

which told me 10.2.0.5. So then I went over to Oracle's website for 64bit drivers:

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html  (select the license agreement and download to /tmp/)

and download the basic 10.2.04 rpm to my /tmp/ folder

cd /tmp/
rpm -ivh oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm

after that was installed I needed to setup the environmental variables just right. If you don't do this your ox_Oracle install will fail silently and you will hit your head against the wall forever..

Tkae note your exact paths might be a little different so check them (incase you have a different version or didn't do the 64bit, etc..

echo export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.4/client64/lib/ >> ~/.bashrc
echo export ORACLE_HOME=/usr/lib/oracle/10.2.0.4/client64 >> ~/.bashrc
echo export PATH=$ORACLE_HOME/bin:$PATH >> ~/.bashrc

This also throws them into the bashrc so they will be there next time. Now it is time to download the ox_Oracle RPM for python. For that go here: http://cx-oracle.sourceforge.net/

Even though I am using RHEL you can just use the CENTOS RPM. So pick your version of oracle and python. If you don't know your version of python run: python -V

wget http://downloads.sourceforge.net/project/cx-oracle/5.1/cx_Oracle-5.1-10g-py26-1.x86_64.rpm?r=http%3A%2F%2Fcx-oracle.sourceforge.net%2F&ts=1377121971&use_mirror=superb-dca2

Now install

rpm -ivh cx_Oracle-5.1-10g-py26-1.x86_64.rpm

Yay!! You did it! You are awesome! You saved hours and hours of time compared to everyone else that has tried this! Congrats, you are a genius, epic genius. Well... maybe... to really know if all of this is true try this:

python -c "import cx_Oracle"

If that works with no errors you did it! Now for some more robust testing try actually doing a simple select statement. Let's try the one we started with. Make a file called connect.py and put this in it.

vi connect.py

Once that opens then copy this in, and of course populate with your connection info. Then save.

import sys
import cx_Oracle

host='yourhostname'
sid='yourSID'
username='yourUserName'
password='yourPassWord'
dsn = cx_Oracle.makedsn(host, 1521, sid)
con = cx_Oracle.connect(username+'/'+password+'@' + dsn)
cur = con.cursor()

cur.execute('Select * from v$version')
for result in cur:
    print result
print con.version

cur.close()
con.close()
print "I am awesome!"

and test

python connect.py

5 comments:

over.unity said...

you are awesome!
great, thank you!

ajax78 said...

Thanks a lot for tutorial.

live n let live said...

From which user I need to run this ? As I tried from root user. It failed

live n let live said...

From any try ending up this : distutils.errors.DistutilsSetupError: cannot locate Oracle include files

Can u guide please ..

Unknown said...

THANK YOU SO MUCH
You saved me a lot of time