Issue building cx_Oracle - libclntsh.so.11.1 => not found
build, cx-oracle, oracle, python
Solution
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/
Problem
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.