pyautogui.screenshot()でエラー

実現したいこと

pyautoguiでスクリーンショットを取れるようにしたい。

発生している問題・分からないこと

pyautoguiでスクリーンショットを取ろうとした所、下記のエラーが発生しました。

エラーメッセージ

error

1** Message: 15:17:09.242: Unable to use GNOME Shell's builtin screenshot interface, resorting to fallback X11. 2 3(gnome-screenshot:6247): Gdk-CRITICAL **: 15:17:09.243: gdk_pixbuf_get_from_surface: assertion 'width > 0 && height > 0' failed 4 5(gnome-screenshot:6247): GdkPixbuf-CRITICAL **: 15:17:09.243: gdk_pixbuf_get_width: assertion 'GDK_IS_PIXBUF (pixbuf)' failed 6 7(gnome-screenshot:6247): GdkPixbuf-CRITICAL **: 15:17:09.244: gdk_pixbuf_get_height: assertion 'GDK_IS_PIXBUF (pixbuf)' failed 8*** BUG *** 9In pixman_region32_init_rect: Invalid rectangle passed 10Set a breakpoint on '_pixman_log_error' to debug 11 12 13(gnome-screenshot:6247): GdkPixbuf-CRITICAL **: 15:17:09.245: gdk_pixbuf_get_width: assertion 'GDK_IS_PIXBUF (pixbuf)' failed 14 15(gnome-screenshot:6247): GdkPixbuf-CRITICAL **: 15:17:09.245: gdk_pixbuf_get_height: assertion 'GDK_IS_PIXBUF (pixbuf)' failed 16 17(gnome-screenshot:6247): Gtk-CRITICAL **: 15:17:09.422: gtk_window_resize: assertion 'width > 0' failed 18 19** (gnome-screenshot:6247): CRITICAL **: 15:17:09.425: Unable to capture a screenshot of any window 20Traceback (most recent call last): 21 File "/home/○○○/.local/lib/python3.9/site-packages/PIL/ImageGrab.py", line 70, in grab 22 size, data = Image.core.grabscreen_x11(xdisplay) 23OSError: X get_image failed: error 8 (73, 0, 1314) 24 25During handling of the above exception, another exception occurred: 26 27Traceback (most recent call last): 28 File "/home/○○○/test.py", line 3, in <module> 29 screen_shot = pyautogui.screenshot() 30 File "/home/○○○/.local/lib/python3.9/site-packages/pyscreeze/__init__.py", line 603, in _screenshot_linux 31 im = ImageGrab.grab() # use Pillow's grab() for Pillow 9.2.0 and later. 32 File "/home/○○○/.local/lib/python3.9/site-packages/PIL/ImageGrab.py", line 80, in grab 33 im = Image.open(filepath) 34 File "/home/○○○/.local/lib/python3.9/site-packages/PIL/Image.py", line 3309, in open 35 raise UnidentifiedImageError(msg) 36PIL.UnidentifiedImageError: cannot identify image file '/tmp/tmpiwe_s3ck.png'

該当のソースコード

Python

1import pyautogui 2 3screen_shot = pyautogui.screenshot() 4screen_shot.save('test.png')

試したこと・調べたこと

上記の詳細・結果

Googleでpyautoguiのエラーについて検索しましたが、自分が見つけたものはすべてうまく行きませんでした。
また、seleniumを使って、Linuxアプリのgoogle chromeを開いて、その後にスクリーンショットを取ろうとしましたがこれもできませんでした。

補足

・chromebook
・pillow 10.2.0
・PyAutoGUI 0.9.54
・opencv-python 4.9.0.80
・Python 3.9.2

コメントを投稿

0 コメント