471,596 Members | 1,154 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

Finding dynamic libraries

Hi,

Is there a way to tell an executing python script where to look for
dynamically-loaded libraries?

My situation is that that I am developing python wrappers for a large
software project. I create python wrappers with swig, and those
extension modules link against dynamic libraries from the project. I
have many test scripts that I would like to be able to run *prior* to
installing these libraries into a standard location.

I have tried altering the LD_LIBRARY_PATH and DYLD_LIBRARY_PATH
environment variables, both by direct assignment of os.environ and by
calling os.putenv(), but neither results in python being able to find
my dynamic libraries.

Thanks in advance

** Bill Spotz **
** Sandia National Laboratories Voice: (505)845-0170 **
** P.O. Box 5800 Fax: (505)284-5451 **
** Albuquerque, NM 87185-0370 Email: wf*****@sandia.gov **

Sep 15 '06 #1
6 1693
Bill Spotz wrote:
Is there a way to tell an executing python script where to look for
dynamically-loaded libraries?
If I understand, you want to tell an already running python process to
import some extensions from arbitrary locations? If that is correct,
you could use a file to hold the dynamic load paths (e.g.,
path-per-line), and then before you want to import the extensions do
something like:

load_file = file('paths')
for path in load_file.read().split("\n"):
if not path in sys.path:
sys.path.insert(0, path)
load_file.close()

Regards,
Jordan

Sep 16 '06 #2
MonkeeSage wrote:
Bill Spotz wrote:
>Is there a way to tell an executing python script where to look for
dynamically-loaded libraries?

If I understand, you want to tell an already running python process to
import some extensions from arbitrary locations?
No, his extensions link against other shared libraries which are not Python
extensions. Those shared libraries are in nonstandard locations because he is
running his tests before installing the libraries and his Python code.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Sep 16 '06 #3
Robert Kern wrote:
No, his extensions link against other shared libraries which are not Python
extensions. Those shared libraries are in nonstandard locations because he is
running his tests before installing the libraries and his Python code.
In that case, couldn't it be done by placing a copy/symlink to the
shared library in the same directory as the python extension, then
reload()'ing the extension from the already running python process? I
think, but am not certain, so don't hold me to it, that dlopen and
kindred will search the working directory for a library before falling
back to the cache or LD_LIBRARY_PATH and so on. Worth a shot mabye.

Regards,
Jordan

Sep 17 '06 #4
MonkeeSage wrote:
Robert Kern wrote:
>No, his extensions link against other shared libraries which are not Python
extensions. Those shared libraries are in nonstandard locations because he is
running his tests before installing the libraries and his Python code.

In that case, couldn't it be done by placing a copy/symlink to the
shared library in the same directory as the python extension, then
reload()'ing the extension from the already running python process? I
think, but am not certain, so don't hold me to it, that dlopen and
kindred will search the working directory for a library before falling
back to the cache or LD_LIBRARY_PATH and so on. Worth a shot mabye.
It depends on the OS. Most Linux systems do not.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Sep 17 '06 #5
Robert Kern wrote:
It depends on the OS. Most Linux systems do not.
Hmm. Looks like 'man dlopen' confirms that (on my box anyway). It looks
like the working directory is never searched at all (unless it is
explicitly listed somewhere). Bummer. What about using ldconfig -l?

Regards,
Jordan

Sep 17 '06 #6
MonkeeSage wrote:
Robert Kern wrote:
>It depends on the OS. Most Linux systems do not.

Hmm. Looks like 'man dlopen' confirms that (on my box anyway). It looks
like the working directory is never searched at all (unless it is
explicitly listed somewhere). Bummer. What about using ldconfig -l?
Doesn't exist on one of the platforms the OP is using, namely OS X.

It's simple enough to write a wrapper script around one's test runner that will
set {DYLD,LD}_LIBRARY_PATH before starting the python executable.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Sep 17 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by mr_burns | last post: by
3 posts views Thread by iceColdFire | last post: by
1 post views Thread by John S Dalzell | last post: by
2 posts views Thread by ElkGroveR | last post: by
11 posts views Thread by toton | last post: by
1 post views Thread by zpinhead | last post: by
1 post views Thread by dfj225 | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.