pyinstaller: ModuleNotFoundError: 没有名为“cv2”的模块; (conda安装opencv)

发布于 2025-01-14 16:11:14 字数 907 浏览 1 评论 0原文

注意:这与这个问题非常相似:pyinstaller: ModuleNotFoundError: No module named 'cv2'

我有一个应用程序,可以通过 IDE/命令行正常工作,但是当我将其转换为 .exe(通过 pyinstaller)时,一切正常,直到.exe 尝试运行 import cv2 行,导致 ModuleNotFoundError:没有名为“cv2”的模块

我的不同之处在于,我受到公司内部流程的限制,必须通过conda install opencv安装opencv(版本4.0.1);因此,上述问题的公认答案(通过 pip install opencv-python 重新安装)将不起作用。

有谁知道我可以通过更改 .spec 文件、添加 hook-*.py 文件、更改 .pyd 文件的位置或其他任何方式来修复此错误?谢谢你!

环境:

  • python 3.8.10
  • pyinstaller 3.6
  • opencv 4.0.1
  • C:\Anaconda\envs\{env_name}\lib\site-packages 我有一个 cv2.cp38- win_amd64.pyd 文件
  • C:\Anaconda\envs\{env_name}\library\include 我有一个opencv2 文件夹包含 .hpp 文件以及其中包含更多 .hpp 文件的文件夹。

Note: This is very similar to this question: pyinstaller: ModuleNotFoundError: No module named 'cv2'

I have an application that works fine via my IDE/ command line, but when I transform this to a .exe (via pyinstaller) everything works fine until the .exe tries to run the line import cv2 resulting in ModuleNotFoundError: No module named 'cv2'.

The difference I have is that I am restricted by my companies internal processes and must install opencv (version 4.0.1) via conda install opencv; thus the accepted answer to above question (reinstall via pip install opencv-python) will not work.

Does anyone know of any way I can fix this error by altering my .spec file, adding a hook-*.py file, altering locations of .pyd file or anything else? Thank you!

Environment:

  • python 3.8.10
  • pyinstaller 3.6
  • opencv 4.0.1
  • In C:\Anaconda\envs\{env_name}\lib\site-packages I have a cv2.cp38-win_amd64.pyd file
  • In C:\Anaconda\envs\{env_name}\library\include I have a opencv2 folder containing .hpp files and folders with further .hpp files within.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文