PyAutoGUI - 没有这样的文件或目录错误

PyAutoGUI - No Such File or Directory Error

有人对此有好感吗?我很想重新创建这个 [tutorial code][1] :

>>> import pyautogui
>>> button7location = pyautogui.locateOnScreen('calc7key.png')
>>> button7location
(1416, 562, 50, 41)
>>> button7x, button7y = pyautogui.center(button7location)
>>> button7x, button7y
(1441, 582)
>>> pyautogui.click(button7x, button7y)

但是我收到以下错误 [在上面代码的第 2 行] FileNotFoundError: [Errno 2] No such file or directory: 'calc7key.PNG' 当我将这样的文件存储在文件 "C:\Users*******\Desktop\Python\lib\site-packages\pyscreeze__init__.py" 中时,第 165 行,在 _locateAll_python needleFileObj = 打开(needleImage,'rb') FileNotFoundError: [Errno 2] No such file or directory: 'calc7key.PNG' ..任何人都可以使用它。本质上,我正在尝试截取一个由 py​​autogui 打开的最小化选项卡(比如屏幕底部的 google chrome 图标)

已解决:必须更改到它所在的目录

>>> import os
>>> os.chdir (r'C:\******')
>>>button7location = pyautogui.locateOnScreen('calc7key.png')

我安装了 open cv:pip install opencv-python

(https://pypi.org/project/opencv-python/)

显示安装 openCV 的建议