简体   繁体   English

pyautogui,屏幕截图 function 无法识别已安装的 Pillow 模块

[英]pyautogui, screenshot function doesn't recognize installed Pillow module

I want to execute this code in Pycharm我想在 Pycharm 中执行这段代码

x, y = pyautogui.locateCenterOnScreen('LVL35.png')

But I get this message但我收到这条消息

ImportError: Pillow module must be installed to use screenshot functions on Windows.

The thing is, I use anaconda and Pillow is already installed and I can also find it in the Project Interpreter settings.问题是,我使用 anaconda 并且 Pillow 已经安装,我也可以在 Project Interpreter 设置中找到它。

Requirement already satisfied: Pillow in c:\anaconda3\lib\site-packages (4.2.1)

Any idea?任何的想法?

在此处输入图像描述

That's almost a bit embarassing, but in case anyone of you has the same problem, just update your Pillow package.这几乎有点尴尬,但如果你们中的任何人遇到同样的问题,只需更新您的 Pillow 包。

pip install Pillow --upgrade

Pillow-4.2.1 was on my system, it upgraded to Pillow-5.1.0 and now everything works just fine. Pillow-4.2.1 在我的系统上,它升级到 Pillow-5.1.0,现在一切正常。

In case anyone has this problem and couldn't fix it with the previous solution regarding the installed version, try uninstalling and installing it back, it worked for me.如果有人遇到此问题并且无法使用有关已安装版本的先前解决方案修复它,请尝试将其卸载并重新安装,它对我有用。 I checked the version I had (8.0) and the version it installed back was the same, so no changes on the version aspect, but for some reason it was failing with the same error message OP was getting and now it isn't.我检查了我拥有的版本 (8.0) 并且它安装的版本是相同的,所以版本方面没有变化,但由于某种原因它失败了,OP 收到了相同的错误消息,现在不是。

  • Windows 10视窗 10
  • Anaconda 1.9.12蟒蛇 1.9.12
  • PyAutoGui 0.9.52 PyAutoGui 0.9.52
  • Pillow 8.0枕头 8.0

If you are installing it using pip , then it will cause the mentioned issue at it imports an older version of Pillow.如果您使用pip安装它,那么它会在导入旧版本的 Pillow 时导致上述问题。 You can either upgrade the version using pip upgrade --Pillow or you can directly install pyautogui directly from PyCharm project settings.您可以使用pip upgrade --Pillow升级版本,也可以直接从 PyCharm 项目设置中直接安装pyautogui Follow the following steps:请按照以下步骤操作:

File -> Settings -> Project name -> Python Interpreter -> + -> Type pyautogui -> Install Package文件 -> 设置 ->项目名称-> Python 解释器 -> + ->输入 pyautogui -> 安装包

You can use the pyscreeze module您可以使用pyscreeze模块

import pyscreeze
x, y = pyscreeze.locateCenterOnScreen('LVL35.png')

Thanks谢谢

I had the same problem.我有同样的问题。 The solution I found was that old maxim in the "Restart the tool" area.我找到的解决方案是“重新启动工具”区域中的旧格言。 In my case I was using PyCharm.就我而言,我使用的是 PyCharm。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM