I am using a python package name cx_Oracle, it's depends oracle instantclient dynamic shared library libclntsh.so.11.1
[wangxw@rhel7 ~]$ ldd /usr/lib64/python2.7/site-packages/cx_Oracle.so
linux-vdso.so.1 => (0x00007fffea5fe000)
libclntsh.so.11.1 => not found
libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0 (0x00007f5c02bbe000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f5c029a2000)
libc.so.6 => /lib64/libc.so.6 (0x00007f5c025e0000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f5c023db000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f5c021d8000)
libm.so.6 => /lib64/libm.so.6 (0x00007f5c01ed6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5c031c1000)
And I'm set LD_LIBRARY_PATH to oracle instantclient's home in bash, It's works fine:
[wangxw@rhel7 ~]$ export LD_LIBRARY_PATH=/home/wangxw/instantclient
[wangxw@rhel7 ~]$ python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>>
But when set LD_LIBRARY_PATH in python, it doesn't work:
[wangxw@rhel7 ~]$ python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import os
>>> os.environ['LD_LIBRARY_PATH'] = '/home/wangxw/instantclient'
>>> 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
>>>
I'm curious about how python load the libclntsh.so.11.1, and how can I load the file in python instead of in bash.
LD_LIBRARY_PATH;import cx_Oracleis looking for a valid Python module in a directory in the Python path, which can be modified via thePYTHONPATHenvironment variable. A.sofile is just type of file that could contain a valid Python module, along with.py,.pyc, and.pyofiles.libclntsh.so.11.1) was not. I guess after python foundcx_OracleinPYTHONPATH,then thecx_Oracleload thelibclntsh.so.11.1byLD_LIBRARY_PATH