28

I'm trying to build cx_Oracle for a Python 2.7.2 and Oracle 11g installation but the built cx_Oracle.so cannot find libclntsh.so.11.1 so importing cx_Oracle in Python fails.

/mypath/cx_Oracle-5.1.1/build/lib.linux-x86_64-2.7-11g]$ ldd cx_Oracle.so
    libclntsh.so.11.1 => not found
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00002ae9be290000)
    libc.so.6 => /lib64/libc.so.6 (0x00002ae9be4ab000)
    /lib64/ld-linux-x86-64.so.2 (0x000000389b600000)

I have libclntsh.so.11.1 in my Oracle client installation directory:

/apps/oracle/client/11.2.0.1/home1/lib]$ ls -l libclntsh.so*
libclntsh.so -> /apps/oracle/client/11.2.0.1/home1/lib/libclntsh.so.11.1
libclntsh.so.11.1

And the cx_Oracle setup.py is picking this lib dir up:

/mypath/cx_Oracle-5.1.1]$ python2.7 setup.py build
/apps/oracle/client/11.2.0.1/home1/
running build
running build_ext
building 'cx_Oracle' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/apps/oracle/client/11.2.0.1/home1/rdbms/demo -I/apps/oracle/client/11.2.0.1/home1/rdbms/public -I/apps/bweb/python-2.7.2/include/python2.7 -c cx_Oracle.c -o build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -DBUILD_VERSION=5.1.1
In file included from /apps/oracle/client/11.2.0.1/home1/rdbms/public/oci.h:3024,
                 from cx_Oracle.c:10:
/apps/oracle/client/11.2.0.1/home1/rdbms/public/ociap.h:10788: warning: function declaration isn't a prototype
/apps/oracle/client/11.2.0.1/home1/rdbms/public/ociap.h:10794: warning: function declaration isn't a prototype
gcc -pthread -shared build/temp.linux-x86_64-2.7-11g/cx_Oracle.o -L/apps/oracle/client/11.2.0.1/home1/lib -lclntsh -o build/lib.linux-x86_64-2.7-11g/cx_Oracle.so

Is something obviously wrong with this setup?

Thanks

UPDATE

My LD_LIBRARY_PATH contains the lib directory above with libclntsh.so.11.1

$ echo $LD_LIBRARY_PATH
/apps/oracle/client/11.2.0.1/lib

This doesn't seem to make any difference. I rebuild the cx_Oracle.so file and it still shows libclntsh.so.11.1 => not found when I run $ ldd cx_Oracle.so.

Python failing to load the built module:

Python 2.7.2 (default, Jan 19 2012, 14:38:32)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory

SOLVED

The issue was related to the LD_LIBRARY_PATH environment variable. Due to restrictions on the setup I'm working with (corp env) I had to build cx_Oracle as another user (system account). i.e. I was running this:

$ sudo -u username python27 setup.py build

So even though LD_LIBRARY_PATH was set correctly for me, my version wasn't used when command was executed as a different user. I was able to build successfully by moving the source code to a location where I had permissions and running the build as my user.

Alex
  • 363
  • 1
  • 3
  • 9

4 Answers4

28

Add /apps/oracle/client/11.2.0.1/home1/lib/ to your LD_LIBRARY_PATH environment variable execute the command below in the terminal before running python or add it into your .bashrc

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/apps/oracle/client/11.2.0.1/home1/lib/
Rob Kielty
  • 7,740
  • 7
  • 37
  • 50
Meitham
  • 8,311
  • 4
  • 32
  • 43
  • which OS are you using? Some UNIX distributions use `LD_LIB_PATH` rather than `LD_LIBRARY_PATH`? You might also want to check the permissions on the file and make sure it's readable by your script. – Meitham Jul 25 '12 at 16:40
  • 1
    RHEL 6. I think LD_LIBRARY_PATH is correct, but it seems it's not being taken into consideration when the build of cx_Oracle happens for some reason. – Alex Jul 25 '12 at 16:42
  • Thanks. I've tried this and it doesn't seem to resolve. I've set the LD_LIBRARY_PATH and built cx_Oracle.so again. Still shows libclntsh.so.11.1 => not found. Confirmed it's set in Python interpreter, and am unable to load cx_Oracle due to the above issue. The problem is at the point of building cx_Oracle, correct? `os.environ['LD_LIBRARY_PATH']` `'/apps/oracle/client/11.2.0.1/lib` `>>> import cx_Oracle Traceback (most recent call last): File "", line 1, in ` `ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory` – Alex Jul 25 '12 at 16:47
  • 1
    I noticed that in the comment just above, os.environ['LD_LIBRARY_PATH'] is '/apps/oracle/client/11.2.0.1/lib', whereas in the rest of the question the shared library appears to be in /apps/oracle/client/11.2.0.1/home1/lib/. Make sure you are pointing to the right directory. – Matt Jul 25 '12 at 18:24
  • Thanks Matt - I made a typo in my comment above whilst trying to format correctly with Markdown. It was pointing to the correct location. I've found the issue now - I'll update my question with the solution and accept this answer as it was the fundamental issue. – Alex Jul 26 '12 at 06:28
1

Yes. You forgot to tell your loader cache tool that it needs to look in that directory for libraries. Add that directory to /etc/ld.so.conf or a similar file and run ldconfig.

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
  • Thanks. I've already set **LD_LIBRARY_PATH** to include this lib directory - would this achieve the same thing? I can't edit /etc/ld.so.conf or similar as do not have privileges. – Alex Jul 25 '12 at 16:24
  • For now, but you *really* should talk to the sysadmin. – Ignacio Vazquez-Abrams Jul 25 '12 at 16:26
  • 1
    On Fedora 20, LD_LIBRARY_PATH didn't cut it for me, but /etc/ld.so.conf.d/ worked: echo /usr/lib/oracle/12.1/client64/lib > /etc/ld.so.conf.d/oracle.conf; ldconfig – Catherine Devlin Sep 11 '14 at 21:11
0

Many oracle products install oraenv. It will set, among other environment variables, LD_LIBRARY_PATH, so consider running . oraenv instead of setting your environment manually.

Ekevoo
  • 2,674
  • 1
  • 22
  • 35
0

Set the LD_RUN_PATH. ( LD_RUN_PATH is used by the linker to specify where to look for libraries only at run time.)

Now build cx_Oracle.

/mypath/cx_Oracle-5.1.1]$ export LD_RUN_PATH="/apps/oracle/client/11.2.0.1/home1/lib"
/mypath/cx_Oracle-5.1.1]$ python2.7 setup.py build

This will not require the setting of LD_LIBRARY_PATH while importing cx_Oracle.

RoshP
  • 19
  • 1
  • 4