问题描述
本人需要将有导入torch包的python文件通过pyinstaller打包生成exe pyinstaller命令使用D参数,即生成一个dist文件夹,里面包含exe和需要调用的dll 打包显示成功,但是运行exe会报如下错误:
Traceback (most recent call last):
File "numpy\core\__init__.py", line 22, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "numpy\core\multiarray.py", line 12, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "numpy\core\overrides.py", line 7, in <module>
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "yolov4_pt2onnx_v6.py", line 2, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "torch\__init__.py", line 190, in <module>
from torch._C import *
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "numpy\__init__.py", line 150, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "numpy\core\__init__.py", line 48, in <module>
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "my_path\my_exe.exe"
* The NumPy version is: "1.21.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
解决方案
本人在网上查询了一堆资料,方法基本都是对numpy包升级或者降级,还有少数是设置环境变量等等,但是本人全部试了一遍,对我都没有用。 最终在一个Stackoverflow平台上看到有人提出可以将anaconda中的mkl开头的dll复制到numpy/core目录下 于是我将dist目录下带有mkl的dll移动到numpy/core目录下,试着运行了下,竟然成功了!
参考资料: ImportError: DLL load failed when importing Numpy installed in conda virtual environment
Tip: 本人环境配置: RTX3060 Win10 cuda11.1 Python3.8 Pytorch1.7.1
|