我正在尝试创建一个在Windows上运行但不安装python的可执行python程序,为此,我正在使用cx_Freeze。但是出现以下错误:“无法加载mkl_intel_thread.dll”
在安装了python的PC(miniconda3)上,我使用cx_Freeze构建了可执行文件,当我运行该可执行文件时,我还会得到“无法加载mkl_intel_thread.dll”的信息。我通过转到python文件夹Library \ bin修复了此问题,并将mkl_intel_thread.dll文件复制到了放置可执行文件的位置。问题是,即使mkl_intel_thread.dll位于文件夹中,当将整个文件夹移至另一台PC(未安装python)时,此错误仍然会出现。
我要分发的文件(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.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)
答案 0 :(得分:2)
编辑:
尝试将在mkl
或Library\bin
下找到的numpy\core
开头的所有文件以及libiomp5md.dll
复制到构建文件夹,请参阅{{3 }}和Python Pyinstaller 3.1 Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll。
一旦发现需要手动复制的文件,您可以使用{{的cx_Freeze
}列表,让include_files
包括必要的文件。 1}}选项(请参见下面的代码段)。如有必要,您可以使用元组build_exe
作为(source, destination)
列表中的项目,以使include_files
将文件从cx_Freeze
复制到特定的source
中目录,请参见destination
cx_freeze converted GUI-app (tkinter) crashes after pressing plot-Button。
我在问题中发布的设置脚本中看到了其他潜在问题:
cx_Freeze
选项的numpy
列表包含整个packages
软件包,这更容易,也可能更安全build_exe
5.1.1,TCL / TK DLL必须包含在构建目录的cx_Freeze
子目录中总而言之,请尝试使用
lib
在您的设置脚本中。
答案 1 :(得分:1)
类似的问题会影响cx_Freeze 6.1或6.2:可执行文件无法启动,无论是没有错误消息还是带有
INTEL MKL错误:找不到指定的模块。 mkl_intel_thread.dll。
英特尔MKL致命错误:无法加载mkl_intel_thread.dll。
配置:
使用Python 3.6.8或更早版本的numpy(例如, 1.18.4 + mkl或1.19.0 + mkl。
我观察到cx_Freeze在构建目录的子目录mkl_rt.dll
中包含3个DLL python38.dll
,vcruntime140.dll
和lib\numpy\core
,而原始安装不包含子目录site-packages\numpy\core
中的任何DLL(所有DLL在site-packages\numpy\DLLs
中)。如果在使用cx_Freeze构建应用程序后,从构建目录的mkl_rt.dll
子目录中手动删除lib\numpy\core
,问题将消失并且该应用程序可以正常工作。
可以通过在setup.py
脚本的末尾添加以下代码来实现此解决方案:
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)
其中dist_dir
是cx_Freeze生成的构建目录(传递给build_exe
选项)。
答案 2 :(得分:0)
只需将这四个文件复制到cx_freeze
生成的构建文件夹中
mkl_core.dll
mkl_def.dll
mkl_intel_thread.dll
mkl_mc3.dll
答案 3 :(得分:0)
在使用 cx_Freeze==6.5.3 时,通过将 numpy==1.18.2 从 numpy==1.19.1 降级,设法找到解决方案。