Issue building cx_Oracle – libclntsh.so.11.1 => not found
Question:
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.
Answers:
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
.
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/
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.
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.
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)
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.
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
.
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/
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.
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.
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)