PyautoGUI调用locateOnScreen报错 已安装Pillow仍提示缺失问题解决
PyAutoGUI调用locateOnScreen方法报错解决方案
问题描述
使用PyAutoGUI的locateOnScreen方法定位屏幕元素时触发报错,完整报错信息如下:
Traceback (most recent call last): File "C:\Users\centr\PycharmProjects\phoenix\whatsapp\main.py", line 7, in <module> position1 = pt.locateOnScreen('whatsapp/smiley_paperclip.png') File "C:\Users\centr\PycharmProjects\phoenix\venv\lib\site-packages\pyautogui\_init_.py", line 175, in wrapper return wrappedFunction(*args, **kwargs) File "C:\Users\centr\PycharmProjects\phoenix\venv\lib\site-packages\pyautogui\_init_.py", line 213, in locateOnScreen return pyscreeze.locateOnScreen(*args, **kwargs) File "C:\Users\centr\PycharmProjects\phoenix\venv\lib\site-packages\pyscreeze\_init_.py", line 371, in locateOnScreen screenshotIm = screenshot(region=None) # the locateAll() function must handle cropping to return accurate coordinates, so don't pass a region here. File "C:\Users\centr\PycharmProjects\phoenix\venv\lib\site-packages\pyscreeze\_init_.py", line 143, in wrapper raise PyScreezeException('The Pillow package is required to use this function.') pyscreeze.PyScreezeException: The Pillow package is required to use this function.
排查过程
- 执行
pip install Pillow安装依赖,系统提示包已安装,但报错依然存在 - 确认问题根源为Pillow 8.3.0版本与PyAutoGUI依赖的pyscreeze组件存在兼容性冲突
解决方案
卸载现有高版本Pillow,重装8.0.0版本即可解决,执行命令如下:
- 卸载现有Pillow:
pip uninstall -y pillow - 安装指定版本:
pip install pillow==8.0.0
内容的提问来源于stack exchange,提问作者GabsLeo
相关产品推荐
相关产品推荐

