ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.


 問題:

pyinstaller 打包后,運行生成的exe報錯 “recursion is detected during loading of “cv2“ binary extensions.”

 

Traceback (most recent call last):
  File "Sy.py", line 15, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "cv2\__init__.py", line 180, in <module>
    bootstrap()
  File "cv2\__init__.py", line 152, in bootstrap
    native_module = importlib.import_module("cv2")
  File "importlib\__init__.py", line 126, in import_module
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "cv2\__init__.py", line 180, in <module>
    bootstrap()
  File "cv2\__init__.py", line 75, in bootstrap
    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.

 

========================

使用pip卸載opencv,pip uninstall opencv*******(具體的安裝的opencv的名字)
到%:\python\Lib\site-packages%路徑(安裝的python的路徑)下刪除cv2的文件夾
再用pip重新安裝opencv,pip install opencv****

 

========================

解決方法(可依次嘗試):

1.重裝cv2。(這是回答比較多的,多數情況有用)

先pip unintall opencv-python ,再pip intall opencv-python

2.設置環境變量。

參考:

Python-Opencv [ERROR: recursion is detected during loading of "cv2"_凌空的槳-CSDN博客

3.降低cv2版本。

pyinstaller和cv2的版本存在兼容問題。本人用的pyinstaller是4.7(python3.8.0),cv2是4.5.4.58,結果出錯,把cv2版本降低到4.5.1.48再打包,就不報錯了。

========================

https://wiki.archlinux.org/index.php/Arch_Linux_Archive#How_to_downgrade_one_package

 

========================

open cmd and use pip to install a different version:

 pip install opencv-python==4.5.3.56 

========================

opencv-python      4.5.5.62

========================

 

REF

https://blog.csdn.net/weixin_44205803/article/details/100975762

https://blog.csdn.net/qq_44796370/article/details/121458744

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM