我正在创建一个脚本来在屏幕上查找图像,我的代码如下:
import pyautogui
image = pyautogui.locateOnScreen('my-image.png')
print(image)
图像是打印屏幕,因此图像的比例相同。
当图像不在屏幕上时,我的脚本正在打印None
,但是当图像在屏幕上时,它将返回如下错误:
$ 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
我的代码有什么问题?我正在使用Windows 10 x64。
答案 0 :(得分:3)
这不是您的代码有问题。 pyscreeze
维护者需要更新其代码以使用return
而不是raise StopIteration()
结束其生成器,因为PEP 479在Python 3.7中是enabled for all code,从而改变了{ {1}}在生成器中。