You need to enable JavaScript to run this app. PyautoGUI调用locateOnScreen报错 已安装Pillow仍提示缺失问题解决
优惠活动
大模型
产品
解决方案
定价
更多

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版本即可解决,执行命令如下:

  1. 卸载现有Pillow:pip uninstall -y pillow
  2. 安装指定版本:pip install pillow==8.0.0

内容的提问来源于stack exchange,提问作者GabsLeo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.13 05:27:03