You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyAutoGui locateCenterOnScreen报错:已装Pillow仍提示需该包求助

问题描述

运行以下代码时触发 pyscreeze.PyScreezeException: The Pillow package is required to use this function 错误:

gs_empty_search_btn_x, gs_empty_search_btn_y = pyautogui.locateCenterOnScreen('pictures/shopping/search_bar_empty.png',
                                                                              confidence=.8)
print(gs_empty_search_btn_x)

环境信息

  • 操作系统:Windows
  • IDE:PyCharm Community 2022.2.1
  • 已安装依赖:Pillow 9.2.0、PyAutoGUI 0.9.53

已尝试操作

  • 执行 pip install Pillow 和 pip install --upgrade Pillow,均返回“Requirement already satisfied”
  • 通过PyCharm设置重新安装PyAutoGUI
  • 卸载并重装Pillow
  • 添加 import PIL 语句后手动安装Pillow
  • pip freeze 输出确认 Pillow==9.2.0

解决方案

1. 核对PyCharm的Python解释器

PyCharm可能使用了与系统pip不同的虚拟环境,导致安装的Pillow未关联到当前项目:

  • 打开 File > Settings > Project: [项目名] > Python Interpreter
  • 查看已安装包列表,确认是否存在Pillow。若没有,点击 + 搜索并安装;若已有,点击包名右侧箭头选择Reinstall

2. 强制给项目环境重装Pillow

找到PyCharm项目使用的Python解释器路径(在Python Interpreter设置中可查看),例如 C:\Users\XXX\venv\Scripts\python.exe,在命令行执行:

C:\Users\XXX\venv\Scripts\python.exe -m pip install --force-reinstall Pillow==9.2.0

3. 调整Pillow版本适配PyAutoGUI

PyAutoGUI 0.9.53与部分Pillow版本存在兼容问题,尝试安装指定版本:

pip install Pillow==9.1.0

4. 验证依赖路径匹配

在代码开头添加以下语句,确认Pillow和pyscreeze的环境匹配:

import PIL
print(PIL.__version__)
import pyscreeze
print(pyscreeze.__file__)

若pyscreeze路径不在项目虚拟环境内,说明PyAutoGUI安装在全局环境,需给项目环境重新安装:

C:\Users\XXX\venv\Scripts\python.exe -m pip install pyautogui==0.9.53

内容的提问来源于stack exchange,提问作者Kyle G.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 16:31:36