Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyAutoGui-屏幕捕获:无法将文件写入预期目标_Python_Pyautogui - Fatal编程技术网

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

Python PyAutoGui-屏幕捕获:无法将文件写入预期目标,python,pyautogui,Python,Pyautogui,我试图在我的屏幕上找到一个图像,但它似乎甚至不能保存截图?有什么想法吗 代码: 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>

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

代码:

 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]
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]
screenscapture:无法将文件写入预期目标,.screenshot2018-1106_00-06-22-111441.png
回溯(最近一次呼叫最后一次):
文件“/Users/dirk/Desktop/firsttry/test.py”,第103行,在
a=pyautogui.locateOnScreen('images/toolbox.jpg')
文件“/Users/dirk/Library/Python/2.7/lib/Python/site-packages/pyscreeze/_-init___u;.py”,第265行,在屏幕上的位置
screenshotIm=screenshot(region=None)#locateAll()函数必须处理裁剪以返回准确的坐标,因此不要在此处传递区域。
osx屏幕截图中第331行的文件“/Users/dirk/Library/Python/2.7/lib/Python/site packages/pyscreeze/_init__.py”
im=Image.open(tmpFilename)
文件“/Library/Python/2.7/site packages/PIL/Image.py”,第2609行,打开
fp=内置的.open(文件名为“rb”)
IOError:[Errno 2]没有这样的文件或目录:'.screenshot2018-1106_00-06-22-111441.png'
[在0.8秒内完成,退出代码为1]
[shell_cmd:python-u”/Users/dirk/Desktop/firstry/test.py“]
[dir:/Users/dirk/Desktop/firsttry]
[路径:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:~/.composer/vendor/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin]
  • 转到pyscreeze/\uuuu init\uuuu.py(位于virutalenv或python文件夹中)文件,例如:“/Users/dirk/Library/python/2.7/lib/python/site packages/pyscreeze/\uu init\uuuu.py”

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

  • 删除tempFilename='.screenshot%s.png'中的符号,使其看起来像tempFilename='screenshot%s.png'

这是否与我使用的是python 3.7.1版,但文件夹并不直接指向这一事实有关?如果您是python初学者,您应该从简单的内容开始:pyautogui的功能告诉您如何操作。再次查看。有多个定位功能。不幸的是,这意味着需要更多的工作来定义文件位置,然后最终删除图像,但负责的PyScreeze库在临时文件处理方面写得太简单了。@MichaelButscher睡了一觉,仔细阅读了文档,终于找到了答案,谢谢!这也可能是一个书面许可问题。在我的例子中,我使用Py2App创建了一个.app文件,在运行该应用程序时,它会尝试在没有权限的文件夹中创建临时文件,以避免在
屏幕截图%s.png
前面包含
/users/myuser/documents/