[Solved] ImportError: ERROR: recursion is detected during loading of “cv2” binary extensions. Check OpenCV installation.

Error:
pyinstaller package and run exe error: “recursion is detected during loading of “cv2“ binary extensions.”
Traceback (most recent call last):
  File "Sy.py", line 15, in 
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "cv2\__init__.py", line 180, in 
    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 
    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.

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

Use pip to uninstall opencv, pip uninstall opencv ******* (the name of the specific opencv installation)
Go to the %:\python\Lib\site-packages% path (the path of the python installation) and delete the cv2 folder
Reinstall opencv with pip, pip install opencv****

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

Solution (you can try in sequence).

1. reinstall cv2. (This is the answer more, most cases useful)

first pip unintall opencv-python , then pip intall opencv-python

2. set the environment variables.

3. lower cv2 version.

There is a compatibility problem between pyinstaller and cv2 version. I use pyinstaller is 4.7 (python3.8.0), cv2 is 4.5.4.58, the result is an error, lower the cv2 version to 4.5.1.48 and then package, it does not report an error.

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

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

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

Similar Posts: