python - 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.
解决方案
感谢 Rick M,我发现我的版本太新了,不能很好地相互配合。我使用的有效配置是:
Python 3.5 或 3.7.2(最新于 2019 年 1 月 23 日)
安装程序 3.4
numpy 1.15
推荐阅读
- android - Android - DialogFragment 不显示进入动画
- c# - 错误:ToastNotification 类型在 Windows.Foundation.UniversalApiContract 和 Windows.UI 中都存在
- c# - 在 Unity 中使用 AdMob 实现插页式广告
- python - 爆炸列
- linux - 使用 sed 查找匹配两个日期的一系列行
- c++ - Postgres自定义类型映射到C结构?
- flutter - 有没有办法在 Flutter 上找到连接速度?
- laravel - 我无法显示来自我的控制器的一些信息,我必须在 @section('content') @endsection 之间显示的信息
- php - MySQL PDO 多个 UPDATE
- java - 与 log4j2 集成后,日志未反映在报告门户中