[Numpy-discussion] ctypes: how does load_library work ?

Albert Strasheim fullung at gmail.com
Fri Aug 18 05:40:05 CDT 2006

Hello all

> -----Original Message-----
> From: numpy-discussion-bounces at lists.sourceforge.net [mailto:numpy-
> discussion-bounces at lists.sourceforge.net] On Behalf Of David Cournapeau
> Sent: 18 August 2006 06:55
> To: Discussion of Numerical Python
> Subject: [Numpy-discussion] ctypes: how does load_library work ?
> <snip>
> That works OK, but to avoid the platform dependency, I would like to use
> load_library from numpy: I just replace the cdll.LoadLibrary by :
> _hello = N.ctypeslib.load_library('hello', '.')
> which does not work. The python interpreter returns a strange error
> message, because it says hello.so.so is not found, and it is looking for
> the library in the directory usr/$(PWD), which does not make sense to
> me. Is it a bug, or am I just not understanding how to use the
> load_library function ?

load_library currently assumes that library names don't have a prefix. We
might want to rethink this assumption on Linux and other Unixes.

load_library's second argument is a filename or a directory name. If it's a
directory, load_library looks for hello.<platformspecificextension> in that
directory. If it's a filename, load_library calls os.path.dirname to get a
directory. The idea with this is that in a module you'll probably have one
file that loads the library and sets up argtypes and restypes and here
you'll do (in mylib.py):

_mylib = numpy.ctypeslib.load_library('mylib_', __file__)

and then the library will be installed in the same directory as mylib.py.

Better suggestions for doing all this appreciated. ;-)



More information about the Numpy-discussion mailing list