pyinstaller:ERROR: recursion is detected during loading of “cv2“ binary extensions.

created at 06-14-2022 views: 34

problem

When trying to use the python package pyinstaller to package the .py file, I encountered the following ERROR:

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.

solution

Lower the cv2 version.

My environment:

  • python=3.6.12
  • pyintaller=4.7

There is a compatibility problem between pyinstaller and cv2. Uninstall the existing opencv-python and install opencv-python=4.5.3.56

Then execute the package command and it works perfectly.

created at:06-14-2022
edited at: 06-14-2022: