0

So I am trying to convert my python project to an exe file and run it, but when I do, I get an error like this:

Failed to execute script 'My project' due to unhandled exception: ERROR recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

Traceback (most recent call last):  
  File "Myproject.py", line 3, in module  
  File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module  
  File "cv2\__init__.py", line 180, in module  
  File "cv2\__init__.py", line 75, in bootstrap  
ImportError:
 ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

Here's some of the code:

import pyautogui as pg   
from time import sleep  
import cv2


sleep(1)

pg.hotkey('super', 's')

sleep(0.2)
pg.typewrite('chrome')

sleep(0.3)

pg.press('enter')

sleep(0.4)

pg.typewrite('youtube.com')  
pg.press('enter')
sleep(1)

cords = pg.locateCenterOnScreen('search.png', confidence=0.8)   
pg.click(cords)   
pg.typewrite('a random video')   
pg.press('enter')

any help would be appreciated.

5
  • How did you install OpenCV ? Also.. you import opencv but then you don't use it.. Commented Nov 18, 2021 at 8:22
  • I installed it from the terminal in vs code using pip install opencv-python, also I just saw that, in order for the confidence argument to work, it needs the cv2 module. That is the only reason I have it there. Commented Nov 19, 2021 at 19:11
  • Ok, opencv is necessary.. I didn't know pyautogui. Now.. Is the program working itself or the error is just about the generated exe ? Commented Nov 23, 2021 at 10:32
  • Yes, the program works 100% when it runs as a python file. The problem appears when it's converted to exe. Commented Nov 24, 2021 at 21:18
  • please try with a clean install of both pyinstaller and opencv Commented Nov 26, 2021 at 16:18

3 Answers 3

1

Try uninstalling opencv and installing an older version, like version 4.5.3

Sign up to request clarification or add additional context in comments.

1 Comment

Tried installing an older version of it, but unfortunately I am getting a bunch of errors. but thanks for the suggestion.
1

Just found out the problem.I was using the latest 3.10.0 version of Python and apparently, it had some bugs about numpy and opencv modules.

My Advice:

Never use the latest python version. Always the previous one.

1 Comment

Which version did you use?
0

I also got the same error. I got around the error by lowering the python and opencv versions. I used following versions :

Python 3.9.13
opencv-python==4.5.3.56

I've tried several combinations, but there seems to be no error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.