Find out if/which BLAS library is used by Numpy

numpy.show_config() doesn't always give reliable information. For example, if I apt-get install python-numpy on Ubuntu 14.04, the output of np.show_config() looks like this:

blas_info:
    libraries = ['blas']
    library_dirs = ['/usr/lib']
    language = f77
lapack_info:
    libraries = ['lapack']
    library_dirs = ['/usr/lib']
    language = f77
atlas_threads_info:
  NOT AVAILABLE
blas_opt_info:
    libraries = ['blas']
    library_dirs = ['/usr/lib']
    language = f77
    define_macros = [('NO_ATLAS_INFO', 1)]
atlas_blas_threads_info:
  NOT AVAILABLE
openblas_info:
  NOT AVAILABLE
lapack_opt_info:
    libraries = ['lapack', 'blas']
    library_dirs = ['/usr/lib']
    language = f77
    define_macros = [('NO_ATLAS_INFO', 1)]
...

It looks as though numpy is using the standard CBLAS library. However, I know for a fact that numpy is using OpenBLAS, which I installed via the libopenblas-dev package.


The most definitive way to check on *nix is to use ldd to find out which shared libraries numpy links against at runtime (I don't own a Mac, but I think you can use otool -L in place of ldd).

  • For versions of numpy older than v1.10:

    ~$ ldd /<path_to_site-packages>/numpy/core/_dotblas.so
    

    If _dotblas.so doesn't exist, this probably means that numpy failed to detect any BLAS libraries when it was originally compiled, in which case it simply doesn't build any of the BLAS-dependent components.

  • For numpy v1.10 and newer:

    _dotblas.so has been removed, but you can check the dependencies of multiarray.so instead:

    ~$ ldd /<path_to_site-packages>/numpy/core/multiarray.so
    

Looking at the version of numpy I installed via apt-get:

~$ ldd /usr/lib/python2.7/dist-packages/numpy/core/_dotblas.so 
    linux-vdso.so.1 =>  (0x00007fff12db8000)
    libblas.so.3 => /usr/lib/libblas.so.3 (0x00007fce7b028000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fce7ac60000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fce7a958000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fce7a738000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fce7ca40000)

/usr/lib/libblas.so.3 is actually the start of a chain of symlinks. If I follow them to their ultimate target using readlink -e, I see that they point to my OpenBLAS shared library:

~$ readlink -e /usr/lib/libblas.so.3
/usr/lib/openblas-base/libblas.so.3

numpy.show_config() just tells that info is not available on my Debian Linux.

However /usr/lib/python3/dist-packages/scipy/lib has a subdirectory for blas which may tell you what you want. There are a couple of test programs for BLAS in subdirectory tests.

Hope this helps.


You want to check numpy.show_config() to see what libraries are configured.

With the newest mkl that should show libraries = ['mkl_rt'], before that it should contain several mkl_ libraries. See also here.