pyinstaller: ModuleNotFoundError: 没有名为“cv2”的模块; (conda安装opencv)
注意:这与这个问题非常相似: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论