Python 在屏幕上定位时,生成器引发停止迭代
我正在创建一个脚本来查找屏幕上的图像,我的代码如下:Python 在屏幕上定位时,生成器引发停止迭代,python,pyautogui,Python,Pyautogui,我正在创建一个脚本来查找屏幕上的图像,我的代码如下: import pyautogui image = pyautogui.locateOnScreen('my-image.png') print(image) $ python index.py Traceback (most recent call last): File "C:\Projects\project\lib\site-packages\pyscreeze\__init__.py", line 234, in _locat
import pyautogui
image = pyautogui.locateOnScreen('my-image.png')
print(image)
$ 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
图像是一个打印屏幕,因此图像的比例相同
当图像不在屏幕上时,我的脚本正在打印None
,但当图像在屏幕上时,它会返回如下错误:
import pyautogui
image = pyautogui.locateOnScreen('my-image.png')
print(image)
$ 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
$python index.py
回溯(最近一次呼叫最后一次):
文件“C:\Projects\project\lib\site packages\pyscreeze\\uuuu init\uuuuu.py”,第234行,位于python的\u locateAll\u中
提升停止迭代()
停止迭代
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“index.py”,第3行,在
image=pyautogui.locateOnScreen('my-image.png'))
文件“C:\Projects\project\lib\site packages\pyscreeze\\uuuuu init\uuuuuu.py”,第266行,在屏幕上的位置
retVal=locate(图像、屏幕快照、**kwargs)
文件“C:\Projects\project\lib\site packages\pyscreeze\\uuuuu init\uuuuu.py”,第250行,位于locate中
点=元组(locateAll(针线图像、haystackImage、**kwargs))
运行时错误:生成器引发了StopIteration
我的代码有什么问题?我正在使用Windows 10 x64。您的代码没有问题。
pyscreeze
维护人员需要更新他们的代码,以使用return
而不是raise StopIteration()
来结束他们的生成器,就像Python 3.7中的PEP 479一样,更改生成器中StopIteration
的行为。您的代码没有问题。pyscreeze
维护人员需要更新他们的代码以使用return
而不是raise StopIteration()
来结束他们的生成器,就像Python3.7中的PEP 479一样,改变生成器中StopIteration
的行为。哇,顺便问一下,我能做些什么来获得图像位置?或者唯一的方法就是迁移到使用python 2?哇,顺便问一下,我能做些什么来获得图像位置?或者,唯一的方法是迁移到使用python 2?