Garret Bobby Ferguson
Garret Bobby Ferguson

Reputation: 29

I am trying to use pyautogui and get an error every time i match with an image

I wrote a very simple script just to test out pyautogui:

import pyautogui
import time
time.sleep(2)
x = pyautogui.locateCenterOnScreen('yee.png')
print(x)

this was my code, had it sleep so I could minimize it and go to my desktop to have it match one of my desktop icons, I have tried several different icon images and what happens is that whenever it doesn't get a match, it returns none, as it should, however when it does get a match(I found out it was whenever it matched by repeatedly covering and uncovering the icon when I ran the script) it hands out this error to me:

Traceback (most recent call last):
  File "C:\Users\colem\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py", line 234, in _locateAll_python
    raise StopIteration()
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "yeet.py", line 4, in <module>
    x = pyautogui.locateCenterOnScreen('yee.png')
  File "C:\Users\colem\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py", line 295, in locateCenterOnScreen
    coords = locateOnScreen(image, **kwargs)
  File "C:\Users\colem\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py", line 266, in locateOnScreen
    retVal = locate(image, screenshotIm, **kwargs)
  File "C:\Users\colem\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py", line 250, in locate
    points = tuple(locateAll(needleImage, haystackImage, **kwargs))
RuntimeError: generator raised StopIteration

I cant seem to find help anywhere else on this, does anyone know what the problem could be here?

Upvotes: 2

Views: 1091

Answers (1)

Al Sweigart
Al Sweigart

Reputation: 12939

I'm the maintainer of PyAutoGUI. This was a bug that has been fixed in version 0.9.37, so all you need to do is update pyautogui with pip:

pip install -U pyautogui

Upvotes: 1

Related Questions