If you are getting a message like this:
>>> import cx_Oracle
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: libclntsh.so.11.1: wrong ELF class: ELFCLASS32 |
It means you are having issues with ELF (Executable and Linkable Format)
How to solve em?
First, locate the path to libclntsh.so.11.1 (usually in /usr):
[root@zaguan importaFHdesdeRoble]# find / -name "libclntsh.so.11.1"
/usr/lib/oracle/11.1/client64/lib/libclntsh.so.11.1
/usr/lib64/libclntsh.so.11.1 |
Note the presence of two files. Lets check wether they are for 32bits or 64bits:
[root@zaguan importaFHdesdeRoble]# file /usr/lib/oracle/11.1/client64/lib/libclntsh.so.11.1
/usr/lib/oracle/11.1/client64/lib/libclntsh.so.11.1: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not stripped
[root@zaguan importaFHdesdeRoble]# file /usr/lib64/libclntsh.so
/usr/lib64/libclntsh.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), not stripped |
If your system is 64 bits (check it out with uname -a) you should be using the ELF 64-bit LSB shared object.
So, you can just:
mv /usr/lib64/libclntsh.so.11.1 /usr/lib64/libclntsh.so.11.1__32bits
cp /usr/lib/oracle/11.1/client64/lib/libclntsh.so.11.1 /usr/lib64/libclntsh.so.11.1 |
And now, you will be able to import Oracle library from python:
# python
Python 2.4.3 (#1, Apr 14 2011, 20:41:59)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> |
Or, if you want to do it “the right way”. Put this in a script.sh file and alter
#!/bin/bash
PATH=$PATH:$HOME/bin
ORACLE_HOME=/usr/lib/oracle/11.1/client64
LD_LIBRARY_PATH=/usr/lib/oracle/11.1/client64/lib
export ORACLE_HOME
export LD_LIBRARY_PATH
export PATH
# ALTER HERE with the path to python and the file which has the python code to connect to Oracle
salida=`/usr/bin/python ./pythoncodefile.py` |