Issue building cx_Oracle - libclntsh.so.11.1 => not found
Asked Answered
N

5

29

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.

Neuberger answered 25/7, 2012 at 16:12 Comment(0)
K
29

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/
Kohler answered 25/7, 2012 at 16:27 Comment(5)
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.Kohler
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.Neuberger
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 "<stdin>", line 1, in <module> ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directoryNeuberger
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.Siddra
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.Neuberger
C
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.

Cymene answered 25/7, 2012 at 16:15 Comment(3)
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.Neuberger
For now, but you really should talk to the sysadmin.Cymene
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; ldconfigChalaza
L
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.

Leprous answered 13/8, 2014 at 15:4 Comment(0)
C
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.

Canal answered 3/2, 2017 at 8:39 Comment(0)
C
0

Just adding this here so no one else might waste time with what i did wrong.

So you also have to MAKE SURE you reinstall/isntall cx_ORacle AFTER you install the oracle isntant client -I wasted some time before i tried it and it worked like a charm. My set up was cx_ORacle8 and oracle client 18.5. Also need to export ld library path every time before you run the python script as its (18.5)

Concelebrate answered 22/7, 2022 at 5:28 Comment(2)
All recent versions of cx_Oracle do not need to have Oracle Client libraries or header files available during installation of the pre-built binary wheel packages, or even if compiling from source code. At run time only the Oracle Client libraries are needed - Oracle headers are never needed. Finally, try the most recent version of cx_Oracle because it doesn't necessarily need Oracle Client libraries at runtime. Install with python -m pip install oracledb See the release announcement.Nw
I see , in my case i had to use a bit old version because i was not sure if there were any version dependencies so i just tried to get the one i had to work with what i had. Then again its is just one of the scenario i guess.Concelebrate

© 2022 - 2024 — McMap. All rights reserved.