473,379 Members | 1,032 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 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 1822
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
3
by: iceColdFire | last post by:
Hi, Can someone highlight the difference between static library and bynamic library...and how do .lib and .dll files come up in the picture... Thanks, a.a.cpp++ :-)
1
by: John S Dalzell | last post by:
Hi, I have a C++ app which needs to work with a server on a remote machine. The manufacturer has given us a set of DLL's which provide API calls to send requests to the server and receive an...
3
by: K.S.Liang | last post by:
Hi all, 1> If there are more than one dynamic linking libraries in the file system, how do I know which one is loaded into system? Any C library or system call can tell me which *.so or *.sl is...
4
by: yhebib | last post by:
Hello All, I've been browsing and reading all articles I could find on technet ,msdn and other knowledgeable sources to understand the issue I'm dealing with. However, I did not find so far how...
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
1
by: zpinhead | last post by:
I am unable to get my downloaded extension from pecl to link up with php properly. seems like the php.so I could not use pear install http. pear claimed the extension was already installed....
1
by: dfj225 | last post by:
While my question doesn't pertain specifically to python programming, it is a result of developing a python module, so I'm hoping someone here might have experience with this issue. So, first a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.