我使用的是Python包名cx_Oracle,這是蟒蛇負載*。所以取決於甲骨文instantclient動態共享庫libclntsh.so.11.1
當在導入模塊
[[email protected] ~]$ 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)
而且我設置LD_LIBRARY_PATH
甲骨文instantclient的家在bash,這是正常工作:
[[email protected] ~]$ export LD_LIBRARY_PATH=/home/wangxw/instantclient
[[email protected] ~]$ 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
>>>
但設置蟒蛇LD_LIBRARY_PATH
時,它不工作:
[[email protected] ~]$ 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中加載文件。
Python沒有使用'LD_LIBRARY_PATH'; 'import cx_Oracle'正在Python路徑的一個目錄中尋找一個有效的Python模塊,它可以通過'PYTHONPATH'環境變量修改。 '.so'文件只是一個文件類型,可以包含一個有效的Python模塊以及'.py','.pyc'和'.pyo'文件。 – chepner
謝謝,但我的意思是當cx_Oracle正確加載時,但它的依賴關係('libclntsh.so.11.1')不是。我猜python在'PYTHONPATH'中找到'cx_Oracle'後,'cx_Oracle'通過'LD_LIBRARY_PATH'加載'libclntsh.so.11.1' –