3

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.

2
  • Python isn't using LD_LIBRARY_PATH; import cx_Oracle is looking for a valid Python module in a directory in the Python path, which can be modified via the PYTHONPATH environment variable. A .so file is just type of file that could contain a valid Python module, along with .py, .pyc, and .pyo files. Commented Aug 31, 2017 at 12:23
  • Thanks, but I means when the cx_Oracle was loaded correctly, but it's dependencies(libclntsh.so.11.1) was not. I guess after python found cx_Oracle in PYTHONPATH ,then the cx_Oracle load the libclntsh.so.11.1 by LD_LIBRARY_PATH Commented Sep 19, 2017 at 2:51

1 Answer 1

1

You cannot set LD_LIBRARY_PATH environment variable from inside of a process that is loading modules that requires it. It needs to have been set in the process environment of the parent process variables before executing the application.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I think change the os.environ cannot really change the process's env.
Changing os.environ can change the process's env, but for dynamic loading of .so mdoules, where you can change it from your code is too late, as the operating system only looks for the value of LD_LIBRARY_PATH when the process is first starting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.