opencv error when converting a python file to an .exe file with pyinstaller

Question:

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 "PyInstallerloaderpyimod03_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.

Asked By: Sifuniaris

||

Answers:

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

Answered By: Jos Damen

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.

Answered By: Sifuniaris

Hey I am having this exact same problem and have tried all solutions online. Any advice?

I am using python 3.8.10 and downgraded to opencv-python 4.5.3.56

Answered By: DanMac02