Finding dynamic libraries

B

Bill Spotz

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: (e-mail address removed) **
 
M

MonkeeSage

Bill said:
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
 
R

Robert Kern

MonkeeSage said:
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
 
M

MonkeeSage

Robert said:
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
 
R

Robert Kern

MonkeeSage said:
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
 
M

MonkeeSage

Robert said:
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
 
R

Robert Kern

MonkeeSage said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top