recursion is detected during loading of "cv2" binary extensions

Viewed 13560

I have a small program which return opencv error after compilation by pyinstaller. But without compilation it's work!

I use Python 3.8.10 on Windows 10

Program:

import pyautogui
import numpy as np
import cv2
try:
from PIL import Image
except ImportError:
import Image

screenshot = pyautogui.screenshot('screenshot.png', region=(970, 591, 184, 101)) # start
img = cv2.imread('screenshot.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.bitwise_not(img)

Error:

['C:\Users\n1kro\AppData\Local\Temp\_MEI83642\base_library.zip', 'C:\Users\n1kro\AppData\Local\Temp\MEI83642\lib-dynload', 'C:\Users\n1kro\AppData\Local\Temp\MEI83642']
Traceback (most recent call last):
File "test.py", line 3, in
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "cv2_init
.py", line 180, in
File "cv2_init
.py", line 75, in bootstrap
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation. [3416] Failed to execute script 'test' due to unhandled exception!

I tried to reinstall all, but it is not helped!

Find this post: https://github.com/opencv/opencv/issues/13202 But dont understand, what to do :( Need your help, please!

3 Answers

open cmd and use pip to install a different version:

 pip install opencv-python==4.5.3.56

no problems with pyinstaller after it

I was able to resolve this by uninstalling opencv and installing an older version. Version 4.5.3 worked well.

To get around this issue, you can either:

  • Use an older version of OpenCV (e.g. opencv-python==4.5.3.56 instead of 4.6.0.66) as mentioned by the others.
  • Wait for a new version of PyInstaller and pyinstaller-hooks-contrib (possibly v5.3 and v2022.9 according to https://github.com/pyinstaller/pyinstaller/issues/6964#issuecomment-1193333632).
  • Install and compile the development build of pyInstaller that contains a fix for this issue (see thread in comment linked above).
Related