【问题标题】:Python 3 pyAutoGUI - I can't use screenshot functionsPython 3 pyAutoGUI - 我不能使用截图功能
【发布时间】:2017-09-20 23:27:37
【问题描述】:

我尝试从文档中导入:

import pyautgui
pyautogui.click(pyautogui.locateOnScreen("select.png"))

我在第 2 行得到这些错误:

File "C:\log\WinPython-64bit-3.5.4.0Qt5\python-3.5.4.amd64\lib\site-packages\pyscreeze\__init__.py", line 267, 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:\log\WinPython-64bit-3.5.4.0Qt5\python-3.5.4.amd64\lib\site-packages\pyscreeze\__init__.py", line 314, in _screenshot_win32
im = ImageGrab.grab()

NameError: name 'ImageGrab' is not defined

你能帮忙吗?

【问题讨论】:

    标签: python automation screenshot pyautogui


    【解决方案1】:

    看来你需要导入 ImageGrab

    from PIL import ImageGrab
    

    【讨论】:

    • 好吧,PIL 现在在 Python 3 中已经过时了! pyautogui 需要 python3。所以当我遇到这个问题时,我已经安装了 Pillow 版本 4.2.1。请注意,pyautogui 中的所有功能都可以,除了那些正在制作屏幕截图的功能。非常感谢您的帮助
    • 经过一番研究,我发现Pillow可以有效地替换PIL库,但必须像“import PIL”这样导入!!所以 skr 如果你安装了 Pillow 而不是 PIL,那你是完全正确的
    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2017-03-15
    • 2018-11-19
    • 2022-11-13
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多