[Numpy-discussion] Use numpy.distutils to build fortran with BLAS
Matt Hoffman
hoffmanm at cs.ubc.ca
Wed Aug 28 06:08:02 EDT 2013
I have some fortran code that I would like to build and make accessible
from python which needs to call a few BLAS routines. Building it in a
one-off manner is not a problem, but I can't seem to find a good way to
distribute it in a way that just works.
So really I'm wondering if there is a "correct" way use numpy.distutils in
order to link against the same BLAS libraries used by numpy. I'll paste my
current approach below, but I'm not sure that this is the
best/most-portable way to do it. (And it certainly breaks on MacOS due to
the weird way that macs use rpath.)
Anyway my setup contains something like:
from numpy.distutils.core import setup
from numpy.distutils.system_info import get_info, NotFoundError
from numpy.distutils.misc_util import Configuration
sources = ['foo.f']
extra_info = {}
extra_link_args = []
try:
extra_info = get_info('mkl', 2)
extra_link_args = ['-Wl,-rpath,'+path for path in
extra_info['library_dirs']],
except NotFoundError:
try:
extra_info = get_info('blas', 2)
extra_link_args = ['-Wl,-rpath,'+path for path in
extra_info['library_dirs']],
except NotFoundError:
# couldn't find anything. just fall back to building the
functions we need ourselves.
sources += ['ddot.f']
config = Configuration()
config.add_extension(
sources=sources,
extra_info=extra_info,
extra_link_args=extra_link_args
)
setup(**config.todict())
Thanks!
-matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130828/70030aa3/attachment.html>
More information about the NumPy-Discussion
mailing list