pyinstaller打包含有cv2库的python程序为exe,运行后显示没导入成功

 问题描述,程序中含有cv2库,使用pyinstaller打包成exe后,执行出现闪退,并且报错没导入cv2库,百度得知是cv2版本太高

报错代码: 

raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
[15648] Failed to execute script '调用摄像头' due to unhandled exception!

pyinstaller打包含有cv2库的python程序为exe,运行后显示没导入成功_第1张图片

 

raise ImportError('ERROR: recursion is detected during loading of "cv2" bina

执行下列操作,重新安装低版本cv2后,问题解决

pip uninstall opencv-python
pip install opencv-python==4.5.1.48

pyinstaller打包含有cv2库的python程序为exe,运行后显示没导入成功_第2张图片

 Python程序打包成exe

pip install pyinstaller #安装打包程序
pyinstaller -F 要打包的python程序

pyinstaller打包含有cv2库的python程序为exe,运行后显示没导入成功_第3张图片

 重新打包后程序正常执行

你可能感兴趣的:(Python,python,numpy,开发语言)