PyAutoGui-屏幕截图:无法将文件写入目标位置

时间:2018-11-05 23:13:49

标签: python pyautogui

我正在尝试在屏幕上查找图像,但是似乎无法保存屏幕截图?有什么想法吗?

代码:

pyautogui.locateOnScreen('images/toolbox.jpg')

错误:

 screencapture: cannot write file to intended destination, .screenshot2018-1106_00-06-22-111441.png
Traceback (most recent call last):
  File "/Users/dirk/Desktop/firsttry/test.py", line 103, in <module>
    a = pyautogui.locateOnScreen('images/toolbox.jpg')
  File "/Users/dirk/Library/Python/2.7/lib/python/site-packages/pyscreeze/__init__.py", line 265, in locateOnScreen
    screenshotIm = screenshot(region=None) # the locateAll() function must handle cropping to return accurate coordinates, so don't pass a region here.
  File "/Users/dirk/Library/Python/2.7/lib/python/site-packages/pyscreeze/__init__.py", line 331, in _screenshot_osx
    im = Image.open(tmpFilename)
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 2609, in open
    fp = builtins.open(filename, "rb")
IOError: [Errno 2] No such file or directory: '.screenshot2018-1106_00-06-22-111441.png'
[Finished in 0.8s with exit code 1]
[shell_cmd: python -u "/Users/dirk/Desktop/firstry/test.py"]
[dir: /Users/dirk/Desktop/firsttry]
[path: /opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:~/.composer/vendor/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

1 个答案:

答案 0 :(得分:1)

  • 转到 pyscreeze / __ init __。py (位于virutalenv或python文件夹内)文件,例如:“ / Users / dirk / Library / Python / 2.7 / lib / python / site-packages / pyscreeze / __ init __。py“

  • 导航到第327或331行,在内部函数中: def _screenshot_osx

  • 删除 符号,位于tempFilename ='.screenshot%s.png'中,因此它看起来像tempFilename ='screenshot% s.png'