首页 > 解决方案 > Win10 / Pyinstaller ImportError: numpy.core.multiarray 导入失败

问题描述

概括

我刚刚编写了一个 Python (3.7.2) 程序和一个使用 Pyinstaller (3.4) 将其编译为 exe 的程序。Python 文件使用 opencv-python(需要 numpy)作为依赖项。尽管已经寻找了一段时间,但我在网上看到的解决方案都没有对我有用。

我没有安装 anaconda,也没有我正在使用的任何库的多个版本(包括 Python 本身)。

此外,当我在 python 中运行“from numpy import multiarray”时,即使这样也会打印出无法导入的错误。

我试过的

卸载并重新安装 numpy 和 opencv-python

将 numpy 更新到最新版本(1.16)。

除了我的本机 Windows 10 之外,在 Windows 10 和 7 VM 中的程序上运行 pyinstaller(当然,所有依赖项都是通过 pip 安装的)(快速说明——当我在 Win7 上运行时,我没有得到任何“lib”未找到:'我在Win10中看到的错误,但程序仍然无法运行)

这些结果都没有对我收到的“numpy.core.multiarray 无法导入”的错误消息产生影响。

问题

如何让我的程序编译为 exe?我愿意使用不同的程序(pyinstaller 除外)。

谢谢!!

我有的数据

这是在 python 终端中运行“from numpy import multiarray”的错误消息:

ImportError: cannot import name 'multiarray' from 'numpy' (C:\Users\name\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\__init__.py)

这是尝试运行已编译的 exe 的完整错误消息

PS C:\Users\name\Downloads\py\dist\SignRecorder> .\SignRecorder.exe
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "SignRecorder.py", line 1, in <module>
File "c:\users\name\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\cv2\__init__.py", line 3, in <module>
ImportError: numpy.core.multiarray failed to import
[15208] Failed to execute script SignRecorder

这是 pyinstaller 的最终构建输出

C:\Users\name\Downloads\py\build\SignRecorder\SignRecorder.exe
19881 INFO: Building EXE from EXE-00.toc completed successfully.
19893 INFO: checking COLLECT
19893 INFO: Building COLLECT because COLLECT-00.toc is non existent
19894 INFO: Building COLLECT COLLECT-00.toc
28366 INFO: Building COLLECT COLLECT-00.toc completed successfully.

标签: pythonnumpyopencvpyinstaller

解决方案


感谢 Rick M,我发现我的版本太新了,不能很好地相互配合。我使用的有效配置是:

Python 3.5 或 3.7.2(最新于 2019 年 1 月 23 日)

安装程序 3.4

numpy 1.15


推荐阅读