Pyinstaller numpy "Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll" Pyinstaller numpy "Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll" numpy numpy

Pyinstaller numpy "Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll"


I had the same issue using Pyinstaller and Numpy. By default pyinstaller seems to not take into account numpy binaries so you have to specify it manually. You can add the files editing the ".spec" file "binaries" variable, but that will only work for your current program. If you want it working for all the programs your freeze you should make a "hook" and save it in C:\Python3*\Lib\site-packages\PyInstaller\hooks.

I had to adapt LeonidR's code to make the numpy-hook working. I rewrited it using a more modern, pythonic approach using list comprehensions:

from PyInstaller import log as logging from PyInstaller import compatfrom os import listdirmkldir = compat.base_prefix + "/Lib/site-packages/numpy/core" logger = logging.getLogger(__name__)logger.info("MKL installed as part of numpy, importing that!")binaries = [(mkldir + "/" + mkl, '') for mkl in listdir(mkldir) if mkl.startswith('mkl_')] 

"Binaries" is a list of tuples. The second item of the tuple corresponds to the folder where you want to place the 'dlls'. In this case is empty so it copies them directly in the main folder where your '.exe' is.


I just ran into the same problem. As a workaround I copied the DLL's manually, as described in https://stackoverflow.com/a/34893933/4089081

I'm trying to find a better solution though.


I created a hook-numpy.py to deal with this problem:

from PyInstaller import log as logging from PyInstaller import compatfrom os import listdirlibdir = compat.base_prefix + "/lib"mkllib = filter(lambda x : x.startswith('libmkl_'), listdir(libdir))if mkllib <> []:    logger = logging.getLogger(__name__)   logger.info("MKL installed as part of numpy, importing that!")   binaries = map(lambda l: (libdir + "/" + l, ''), mkllib)

In my case, conda is installing the mkl libraries to speed up numpy and scipy.