简体   繁体   中英

Generator raised StopIteration when locateOnScreen

I'm creating a script to find image on the screen, my code is like this:

import pyautogui

image = pyautogui.locateOnScreen('my-image.png')
print(image)

The image is a print screen, so the scale of the image is the same.

When the image is not on the screen, my script is printing None , but when the image is on the screen, it's returning an error like this:

$ python index.py
Traceback (most recent call last):
  File "C:\Projects\project\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 "index.py", line 3, in <module>
    image= pyautogui.locateOnScreen('my-image.png')
  File "C:\Projects\project\lib\site-packages\pyscreeze\__init__.py", line 266, in locateOnScreen
    retVal = locate(image, screenshotIm, **kwargs)
  File "C:\Projects\project\lib\site-packages\pyscreeze\__init__.py", line 250, in locate
    points = tuple(locateAll(needleImage, haystackImage, **kwargs))
RuntimeError: generator raised StopIteration

What it's wrong in my code? I'm using Windows 10 x64.

It's not a problem with your code. The pyscreeze maintainers need to update their code to use return instead of raise StopIteration() to end their generators, as PEP 479 has been enabled for all code in Python 3.7, changing the behavior of StopIteration in a generator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM