PyAutoGui屏幕捕获:无法将文件写入预期目标

2024-09-26 17:37:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在我的屏幕上找到一个图像,但它似乎不能保存屏幕截图?有什么想法吗?在

代码:

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]

Tags: inpybinpackageslocallinelibrarysite
1条回答
网友
1楼 · 发布于 2024-09-26 17:37:42
  • 转到pyscreeze/\uyu init_u.py(位于virutalenv或python文件夹中)文件,例如:“/Users/dirk/Library/python/2.7/lib/python/site packages/pyscreeze/\uyu init_u.py”

  • 导航到行327或331,在函数内:def\u屏幕截图

  • 删除tempFilename='.screenshot%s.png'中的符号,因此它应该看起来像tempFilename='屏幕快照%s.png'

相关问题 更多 >

    热门问题