Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot load mkl_intel_thread.dll on python executable

I'm trying to create an executable python program that runs on windows without python being installed, for this I'm using cx_Freeze. But I get the following error: "Cannot load mkl_intel_thread.dll"

On my PC, which has python installed (miniconda3), I built the executable using cx_Freeze, and when I ran the executable I also would get "Cannot load mkl_intel_thread.dll". I fixed this by going to my python folder, Library\bin, and copied the mkl_intel_thread.dll file to where the executable is placed. The problem is, when moving the whole folder to another PC (without python installed), this error reappears, even though the mkl_intel_thread.dll is in the folder.

File that I want to distribute (plot.py):

import matplotlib.pyplot as plt

a = [0, 1, 2]
b = [0, 2, 0]
plt.fill(a, b, 'b')
plt.show()

cx_Freeze setup file (setup.py):

import cx_Freeze
import sys
import matplotlib
import numpy
import os

os.environ['TCL_LIBRARY'] = "C:\\Miniconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Miniconda3\\tcl\\tk8.6"


executables = [cx_Freeze.Executable("plot.py")]


build_exe_options = {"includes":['numpy.core._methods',
        'numpy.lib.format', 'matplotlib.backends.backend_tkagg']}

cx_Freeze.setup(
    name = "script",
    options = {"build_exe": build_exe_options},
    version = "0.0",
    description = "A basic example",
    executables = executables)
like image 985
Carlos Avatar asked Jan 24 '19 00:01

Carlos


1 Answers

A similar issue affects cx_Freeze 6.1 or 6.2: the executable does not launch, either without error message or with

INTEL MKL ERROR: The specified module could not be found. mkl_intel_thread.dll.
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.

Configuration:

  • Windows 10
  • Python 3.8.5 installed from https://www.python.org/
  • numpy 1.19.1+mkl installed with pip using wheel from https://www.lfd.uci.edu/~gohlke/pythonlibs/
  • various python modules installed using pip

This is also observed with Python 3.6.8 or earlier versions of numpy such as e.g. 1.18.4+mkl or 1.19.0+mkl.

I've observed that cx_Freeze includes 3 DLLs mkl_rt.dll, python38.dll, and vcruntime140.dll in the subdirectory lib\numpy\core of the build directory, whereas the original installation does not contain any DLL in the subdirectory site-packages\numpy\core (all DLLs are in site-packages\numpy\DLLs). If I manually remove mkl_rt.dll from the subdirectory lib\numpy\core of the build directory after building the application with cx_Freeze, the issue disappears and the application works.

This solution can be implemented by adding the following code at the end of the setup.py script:

numpy_core_dir = os.path.join(dist_dir, 'lib', 'numpy', 'core')
for file_name in os.listdir(numpy_core_dir):
    if file_name.lower().endswith('.dll'):
        file_path = os.path.join(numpy_core_dir, file_name)
        os.remove(file_path)

where dist_dir is the build directory generated by cx_Freeze (passed to the build_exe option).

like image 193
jpeg Avatar answered Oct 30 '22 20:10

jpeg