Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a screenshot of the Raspberry Pi’s desktop, use the capture method supported by its display session—not its camera. On Raspberry Pi OS Bookworm, the default desktop uses Wayland with labwc, and Raspberry Pi documents grim for screen capture. A Python script can run grim as a child process and save the result. Use Picamera2 only when you want an image from a connected camera.

First decide what you want to capture

A desktop screenshot records the image being shown by the desktop compositor. A camera image records what a camera sensor sees. They are different capture paths: a connected camera is not required for a desktop screenshot, and Picamera2 is not the tool for capturing the desktop.

  • Desktop or application window: use the screen-capture route supported by the active display session.
  • A photograph from a Raspberry Pi camera: use Raspberry Pi’s camera software and Picamera2.

The instructions below focus on the desktop, which is what “screenshot” usually means. Before choosing a Python library or command, check the Raspberry Pi OS release, whether the desktop session is Wayland or X11, and whether the Python process is running in the session whose screen you intend to capture. A script launched remotely or outside the interactive desktop session should not be assumed to have access to that screen.

On Raspberry Pi OS Bookworm, use grim from Python

Raspberry Pi’s Bookworm migration guide documents grim for desktop screenshots. Python can invoke it with the standard-library subprocess module; there is no screenshot-specific Python package required for this approach. The code below orchestrates the documented command-line utility. It is not a claim that every compositor or launch environment supports the same capture workflow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
  • Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized

Save the whole display

Run this script from a terminal in the desktop session you want to capture. Change OUTPUT to the destination path you prefer.

from pathlib import Path
import shutil
import subprocess
import sys

OUTPUT = Path.home() / "Pictures" / "raspberry-pi-screen.png"

def main():
    if shutil.which("grim") is None:
        sys.exit("grim was not found. Check that it is installed and available on PATH.")

    OUTPUT.parent.mkdir(parents=True, exist_ok=True)
    result = subprocess.run(
        ["grim", str(OUTPUT)],
        check=False,
        capture_output=True,
        text=True,
    )

    if result.returncode != 0:
        detail = result.stderr.strip() or "grim returned an error without details."
        sys.exit(f"Screenshot failed: {detail}")

    print(f"Saved screenshot to {OUTPUT}")

if __name__ == "__main__":
    main()

Save it as, for example, take_screenshot.py, then run python3 take_screenshot.py. If it succeeds, the script prints the path. The output format follows the filename extension shown here; use a suitable image extension supported by the installed capture utility if you choose another format.

subprocess.run passes the output path as a separate argument rather than building a shell command from a string. That avoids shell-quoting problems for paths containing spaces. The script creates the parent directory if needed and reports the command’s error text when the capture fails.

Rank #2
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
  • Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM)
  • Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
  • CanaKit Premium High-Gloss Raspberry Pi 4 Case with Integrated Fan Mount, CanaKit Low Noise Bearing System Fan
  • CanaKit 3.5A USB-C Raspberry Pi 4 Power Supply (US Plug) with Noise Filter, Set of Heat Sinks, Display Cable - 6 foot (Supports up to 4K60p)
  • CanaKit USB-C PiSwitch (On/Off Power Switch for Raspberry Pi 4)

Select a rectangular area

Raspberry Pi’s Bookworm guide documents slurp | grim -g - for selecting an area. slurp provides the selected geometry; grim uses it for the capture. The guide notes that slurp needs to be installed separately for this workflow. This Python version connects the two processes without invoking a shell:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from pathlib import Path
import shutil
import subprocess
import sys

OUTPUT = Path.home() / "Pictures" / "raspberry-pi-selection.png"

def main():
    for program in ("slurp", "grim"):
        if shutil.which(program) is None:
            sys.exit(f"{program} was not found. Check that it is installed and available on PATH.")

    OUTPUT.parent.mkdir(parents=True, exist_ok=True)

    try:
        selection = subprocess.run(
            ["slurp"],
            check=True,
            capture_output=True,
            text=True,
        )
    except subprocess.CalledProcessError as exc:
        detail = (exc.stderr or "").strip()
        sys.exit(f"Area selection failed or was cancelled. {detail}")

    geometry = selection.stdout.strip()
    if not geometry:
        sys.exit("slurp did not return a selection.")

    result = subprocess.run(
        ["grim", "-g", geometry, str(OUTPUT)],
        check=False,
        capture_output=True,
        text=True,
    )
    if result.returncode != 0:
        detail = result.stderr.strip() or "grim returned an error without details."
        sys.exit(f"Screenshot failed: {detail}")

    print(f"Saved selected area to {OUTPUT}")

if __name__ == "__main__":
    main()

When run, slurp lets you select an area interactively; the script passes its returned geometry to grim. If selection is cancelled or returns no geometry, it stops instead of silently making a full-screen capture.

Check the session before trying PyAutoGUI or scrot

PyAutoGUI’s screenshot documentation describes scrot as its Linux screenshot dependency. That is a qualified route, not a session-independent recommendation: Raspberry Pi OS Bookworm defaults to a Wayland desktop, while older X11-oriented screenshot instructions may not capture Wayland’s compositor output. The exact result depends on the active session and tool configuration; a black image can have other causes too.

Rank #3
ELECROW CrowPi Case Kit for Raspberry Pi 5, 9-Inch Display
  • Not including the Raspberry Pi 5 (8GB), the Crowpi advanced version comes with the Raspberry Pi 5
  • ELECROW Black Case for the Raspberry Pi 5, CrowPi is equipped with a 9-inch HD touchscreen along with a camera; All the regular components used in DIY electronics are packed into the CrowPi development board, such as LCD, LED matrix, buzzer, light sensor, PIR sensor, ultrasonic sensor, IR sensor, etc
  • Raspberry Pi Sensors: The Crowpi raspberry pi 5 programming kit is jam-packed with lots of buttons such as 19 different sensors in a tidy easy to use package; You don't have to wait and wire things
  • Build Quality: Solid ABS shell and well made components in one place make it strong and convenient to travel
  • Programming Lessons: This raspberry pi 5 learning kit ships with step by step instructions and provides 21 lessons to take you through identifying components reading code and running it in the terminal

If you want to use PyAutoGUI, first establish that your session and capture dependency work together. On Bookworm or later, Raspberry Pi advises installing Python packages with pip inside a virtual environment rather than into the system Python environment. A typical setup for a project is:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install pyautogui

PyAutoGUI’s basic capture call is pyautogui.screenshot(). For example, once the library and its Linux screenshot dependency are available in a compatible session:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import pyautogui

image = pyautogui.screenshot()
image.save("pyautogui-screen.png")

If this produces a black or missing capture on a Bookworm Wayland desktop, do not assume adding another Python package will make an X11-oriented capture path compositor-aware. Prefer the documented Bookworm grim route when it is supported by your environment.

Rank #4
CanaKit Raspberry Pi 5 Desktop PC with SSD (Fully Assembled) (256 GB SSD)
  • Fully assembled for plug-and-play operation
  • Includes Raspberry Pi 5 with 8GB RAM
  • 256 GB PCIe Pi NVMe SSD (Pre-loaded with Pi 64-Bit OS)
  • M.2 HAT+
  • CanaKit Turbine Black Case for the Pi 5

Installing Python packages on Bookworm and later

The grim scripts above use Python’s standard library, so they do not need a pip install. If another Python dependency is needed, use an isolated environment rather than installing into the OS-managed Python:

  1. From the project directory, create an environment with python3 -m venv .venv.
  2. Activate it with source .venv/bin/activate.
  3. Install a package with python -m pip install PACKAGE_NAME, replacing the name with the package you actually need.
  4. Run the script with that environment active.

Raspberry Pi also documents apt as a system-package installation route. Use the OS package manager for system utilities and follow the package instructions for the Raspberry Pi OS release you have; the Python virtual environment is for pip-managed project dependencies.

Troubleshoot black, missing, or failed screenshots

  • grim is not found: the utility may not be installed or may not be on the process’s PATH. Check availability with command -v grim in the same terminal used to run Python.
  • grim fails to capture: grim requires a compositor that supports the screencopy protocol. Confirm the active desktop/session and compositor support; the command-line interface by itself does not guarantee compatibility.
  • The image is black with scrot or PyAutoGUI: check whether the desktop is Wayland. PyAutoGUI documents scrot as its Linux route, and an X11-oriented method may not capture Wayland output. The symptom does not prove Wayland is the cause, so also inspect the tool’s error and session setup.
  • Area selection does not start: verify that slurp is installed and available, and run the script in the interactive graphical session where selection is expected.
  • The output file is absent: check the printed error, destination directory permissions, and whether the capture command returned a nonzero status. The examples report stderr rather than treating a failed subprocess as success.
  • It works in a desktop terminal but not over SSH or a service: the process may not be running with access to the target interactive display session. These commands do not grant a remote or headless process desktop access automatically.
  • The picture comes from the wrong source: confirm that you intend to capture the desktop rather than camera sensor output. Use Picamera2 for a supported connected camera, not for a desktop screenshot.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API, not a way to capture the Raspberry Pi’s current desktop. It is an alternative when your actual goal is to capture a web page by URL rather than the Pi display. Its API returns an image or PDF from one GET request. For a webpage screenshot, the Python request can be:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
RasTech Raspberry Pi 5 8GB Kit with Active Cooler and Pi5 Case
  • 【What you Get】You will get 1*Pi 5 8GB Single Board,1*RasTech Case,1*Active Cooler,1*Screwdriver,1*Installation instructions,12-month free warranty, lifetime service, 24-hour prompt and friendly response.
  • 【More Connectors】There are two USB 3.0 ports(5Gbps simultaneously) and two USB 2.0 ports, which triple total bandwidth ,support any combination of up to two cameras or displays. Peak SD card performance is doubled through support for the SDR104 high-speed mode. It provides a smooth desktop experience for you. Offer Gigabit Ethernet and a PCIe interface, along with dual-band Wi-Fi and Bluetooth 5.0/BLE wireless capability. The RasTech Pi 5 Kit use the new 27W 5.1V 5A USB-C power connector.
  • 【 Support Dual 4Kp60 Display 】Each of the two microHDMI sockets can control a 4K display at 60 Hertz, now support HDR, offering super HD video for media streaming projects. RPi 5 is the first RPi model that comes with a PCI Express port (PCIe 2.0 x1 with 500 MB/s) to attach SSDs (requires separate M.2 HAT).
  • 【 Excellent Chips And Applications】Pi 5 is a full-size Pi computer using silicon built in-house at Pi. The RP1 “southbridge” provides the bulk of the I/O capabilities for Pi 5. Pi 5 is more friendly and convenient in the development of Internet of Things, Web development, machine identification, automatic control and other electronic equipment applications and network.
  • 【 Faster CPU, Better GPU 】 Pi 5 features a Broadcom BCM2712 64-bit quad-core Arm Cortex-A76 processor running at 2.4GHz, it delivers a 2–3× increase in CPU performance relative to RaspberryPi 4. The 800MHz VideoCore VII GPU is compatible to OpenGL ES 3.1 and Vulkan 1.2, substantial uplift in graphics performance. Pi 5 Offers lightning-fast CPU speed, a PCI Express interface, a Real Time Clock (RTC) and a power button and runs significantly cooler than Pi 4.
import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

See the ScreenshotNeo API documentation for request options. It removes cookie banners, newsletter popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed; an MCP server lets AI agents take screenshots; and 1,000 screenshots a month are free with no card, with paid plans starting at $5 for 3,000. Learn about ScreenshotNeo or sign up for the free plan.

When to use Picamera2 instead

Picamera2 belongs in a different workflow: taking a picture from a supported Raspberry Pi camera. Raspberry Pi’s camera software documentation and Picamera2 library documentation describe that camera path. It does not replace grim for capturing desktop output. Choose the target first, then use the matching API: compositor capture for the screen, camera software for the sensor.

Frequently Asked Questions

Can a Python screenshot script capture the Raspberry Pi desktop while no user is logged in?

The documented grim workflow relies on a compatible compositor and the intended desktop session. The cited documentation does not establish that a headless or service process can capture an interactive desktop automatically.

Does the Bookworm Print Screen shortcut use the same tool?

Raspberry Pi’s migration guide says Bookworm’s default Print Screen key captures the entire screen into the Pictures folder using grim.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$259.95
Bestseller No. 2
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM); Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
$159.99
Bestseller No. 4
CanaKit Raspberry Pi 5 Desktop PC with SSD (Fully Assembled) (256 GB SSD)
CanaKit Raspberry Pi 5 Desktop PC with SSD (Fully Assembled) (256 GB SSD)
Fully assembled for plug-and-play operation; Includes Raspberry Pi 5 with 8GB RAM; 256 GB PCIe Pi NVMe SSD (Pre-loaded with Pi 64-Bit OS)
$339.97

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.