我使用的是python包名cx_Oracle,它取决于oracle instantclient动态共享库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)
我在bash中将LD_LIBRARY_PATH
设置为oracle instantclient的主页,它的工作正常:
[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
>>>
但是当在python中设置LD_LIBRARY_PATH
时,它不起作用:
[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
>>>
我很好奇python如何加载libclntsh.so.11.1
,如何在python而不是bash中加载文件。
答案 0 :(得分:1)
您无法从正在加载需要它的模块的进程内部设置LD_LIBRARY_PATH
环境变量。在执行应用程序之前,需要在父流程变量的流程环境中设置它。