Quick answer: pygame.error: No available video device means SDL, the library under Pygame, tried every video driver it was built with and none could open a display. The machine has no screen session (SSH, Docker, CI, a service), or the process cannot reach the one that exists. For tests and tools, set SDL_VIDEODRIVER=dummy before Pygame starts. For a real window, give the process a display: a desktop session, xvfb-run, or a working DISPLAY.
Your code is fine. The same script that opens a window on your laptop fails on a server, in a container or over SSH, because Pygame has nowhere to put the window. The error comes from SDL, and SDL decides what to do from two things: which video drivers it was compiled with, and a handful of environment variables. This guide explains that decision, gives you a short script that reports which drivers work on the machine in front of you, and then goes through each environment where the error shows up. Everything here was checked on Pygame 2.6.1 and pygame-ce 2.5.8 on Linux.
- The exact error
- How SDL chooses a video driver
- Find out which drivers work here
- Fix 1: no display at all (SSH, Docker, CI, cron, services)
- Fix 2: a leftover SDL_VIDEODRIVER
- Fix 3: a display exists but the process cannot reach it
- Fix 4: WSL
- Fix 5: Raspberry Pi, bare consoles and Wayland
- Fix 6: hosted environments, macOS and Windows
- Rendering without a window
- How to confirm the fix
- When a player’s machine has no usable display
- Related guides
- Frequently asked questions
The exact error
Traceback (most recent call last):
File "game.py", line 4, in <module>
screen = pygame.display.set_mode((800, 600))
pygame.error: No available video device
It is raised by pygame.display.set_mode() or pygame.display.init(). pygame.init() does not raise it: that function returns a tuple of how many modules started and how many failed, such as (4, 1), and carries on. The exception arrives on the next line that needs the display.
Several nearby messages get confused with it. They have different causes:
| Message | What it means |
|---|---|
pygame.error: No available video device | No driver was requested and none of the built-in ones could start. |
pygame.error: x11 not available (or wayland, kmsdrm, fbcon...) | SDL_VIDEODRIVER names one driver, and that driver could not start or does not exist in this build. |
pygame.error: video system not initialized | A display function was called before the display module was initialised, or after pygame.quit(). A code-order problem, covered in its own guide. |
No protocol specified on stderr | Printed by the X libraries: a display exists and refused this user. See the permissions section below. |
pygame.error: Unable to open a console terminal | From Pygame 1.9 with SDL 1.2’s framebuffer driver. Upgrade to Pygame 2 and read on. |
How SDL chooses a video driver
Pygame 2 is built on SDL 2. When the display module starts, SDL does one of two things.
If the environment variable SDL_VIDEODRIVER is set, SDL tries that one driver. On failure the message is the driver’s name followed by “not available”. The SDL builds in current wheels accept a single name there; a comma-separated list such as x11,wayland is treated as one unknown name.
If the variable is not set, SDL walks its built-in list. On Linux that means X11 (which needs DISPLAY and the system’s X client libraries), then Wayland (which needs WAYLAND_DISPLAY and XDG_RUNTIME_DIR), then others such as KMS/DRM. When every driver in the list fails, you get “No available video device”.
There is one twist that matters on recent versions. The SDL bundled in the Pygame 2.6.1 and pygame-ce 2.5.8 wheels includes an offscreen driver, and on a machine with no display it is the fallback. On those versions set_mode() succeeds with no error and no window. If your script “runs but nothing appears” over SSH, this is why. Builds of SDL without that driver, which include older Pygame 2 wheels and some distribution packages, raise the error instead. Both are the same situation: no usable display.
Find out which drivers work here
Save this as video_check.py and run it in the exact environment that fails (the same user, the same container, the same service):
import os
import pygame
print("pygame", pygame.version.ver, "SDL", pygame.get_sdl_version())
for name in ("SDL_VIDEODRIVER", "DISPLAY", "WAYLAND_DISPLAY", "XDG_RUNTIME_DIR"):
print(f"{name} = {os.environ.get(name)!r}")
saved = os.environ.get("SDL_VIDEODRIVER")
for driver in (None, "x11", "wayland", "kmsdrm", "windows", "cocoa", "offscreen", "dummy"):
if driver is None:
os.environ.pop("SDL_VIDEODRIVER", None)
else:
os.environ["SDL_VIDEODRIVER"] = driver
try:
pygame.display.init()
print(f"{driver or '(default)':10} OK, SDL picked {pygame.display.get_driver()!r}")
except pygame.error as exc:
print(f"{driver or '(default)':10} failed: {exc}")
finally:
pygame.display.quit()
if saved is None:
os.environ.pop("SDL_VIDEODRIVER", None)
else:
os.environ["SDL_VIDEODRIVER"] = saved
In a container with no display, Pygame 2.6.1 prints:
pygame 2.6.1 SDL (2, 28, 4)
SDL_VIDEODRIVER = None
DISPLAY = None
WAYLAND_DISPLAY = None
XDG_RUNTIME_DIR = None
(default) OK, SDL picked 'offscreen'
x11 failed: x11 not available
wayland failed: wayland not available
kmsdrm failed: kmsdrm not available
windows failed: windows not available
cocoa failed: cocoa not available
offscreen OK, SDL picked 'offscreen'
dummy OK, SDL picked 'dummy'
Read it top down. A non-empty SDL_VIDEODRIVER in the first block is suspicious by itself. DISPLAY = None with WAYLAND_DISPLAY = None means there is no desktop session for this process. A (default) line that picks x11, wayland, windows or cocoa means a real window is possible. A line reading “error: XDG_RUNTIME_DIR is invalid or not set in the environment” on stderr is the Wayland attempt failing and is harmless.
Fix 1: no display at all (SSH, Docker, CI, cron, services)
Decide whether you need pixels on a screen.
You do not (unit tests, asset tools, a server process that only uses Pygame for surfaces and rects). Use the dummy driver, and set it before Pygame initialises the display. Before the import is the safe habit:
import os
os.environ["SDL_VIDEODRIVER"] = "dummy"
os.environ["SDL_AUDIODRIVER"] = "dummy"
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
Or from the shell, without touching the code: SDL_VIDEODRIVER=dummy python game.py. The audio variable is the counterpart for machines with no sound card, where pygame.mixer otherwise fails to initialise.
You do (screenshot tests of real rendering paths, code that needs an actual X11 window). Run under Xvfb, a virtual X server:
sudo apt-get install -y xvfb
xvfb-run -a python game.py
In a Dockerfile, install it with the X client libraries. The Pygame wheel bundles SDL but not libX11, which SDL loads from the system at run time, so a slim image cannot use the x11 driver until they are installed:
RUN apt-get update && apt-get install -y --no-install-recommends xvfb libx11-6 libxext6 \
&& rm -rf /var/lib/apt/lists/*
CMD ["xvfb-run", "-a", "python", "game.py"]
In CI the step is the same command: xvfb-run -a python -m pytest. To show a container’s window on a Linux host’s own screen, share the X socket: docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix ....
Fix 2: a leftover SDL_VIDEODRIVER
Old tutorials told people to export SDL_VIDEODRIVER=fbcon or directfb on a Raspberry Pi, or dummy for a test run. SDL 2 has no fbcon driver at all, so on Pygame 2 that setting can only fail:
$ echo $SDL_VIDEODRIVER
fbcon
$ python game.py
pygame.error: fbcon not available
Run unset SDL_VIDEODRIVER, then find where it was set: ~/.bashrc, ~/.profile, /etc/environment, a systemd unit, a Dockerfile ENV line, or an os.environ assignment in the code itself. A leftover dummy is the quiet version: no error, and no window either.
Fix 3: a display exists but the process cannot reach it
- sudo.
sudo python game.pyruns as root, usually without yourDISPLAYandXAUTHORITY, and the X server rejects it (“No protocol specified”). Run the game as your normal user. If root is required for hardware access, fix the device permissions instead, or allow root explicitly withxhost +SI:localuser:root. - SSH. A plain SSH session has no
DISPLAY. To show the window on your own machine, connect withssh -X(your machine needs an X server). To show it on the remote machine’s screen, where the same user is logged in to an X11 desktop, runexport DISPLAY=:0first. - systemd and cron. Services start with an almost empty environment. Run the unit as the desktop user and pass the display through:
[Service]
User=pi
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/pi/.Xauthority
ExecStart=/usr/bin/python3 /home/pi/game/main.py
Start it after the graphical session is up, or it will race the desktop and fail on boot only.
Fix 4: WSL
WSL 2 with WSLg provides a display by itself: echo $DISPLAY prints :0 and Pygame windows appear on the Windows desktop. WSLg comes with Windows 11 and with the Microsoft Store version of WSL on current Windows 10. If DISPLAY is empty, run wsl --update from PowerShell, then wsl --shutdown and reopen the terminal. On WSL 1, or an installation that cannot be updated, there is no built-in display: run an X server on Windows and point DISPLAY at it, or run the game with Windows Python instead.
Fix 5: Raspberry Pi, bare consoles and Wayland
From a desktop session on a Pi, Pygame works like on any Linux desktop. From a console with no desktop (Raspberry Pi OS Lite, a kiosk booting to a TTY), X11 and Wayland are both absent and the only way to draw is KMS/DRM. Run the check script. If the kmsdrm line fails, two things are worth trying:
- Install the distribution’s package,
sudo apt install python3-pygame, and run with the system Python. It links against the system’s SDL 2, which is normally built with KMS/DRM support for that board. Whether the SDL inside a pip wheel can use it varies by wheel, so test instead of assuming. - Check that your user can open the graphics device,
/dev/dri/card0. On Raspberry Pi OS that usually means membership of thevideoandrendergroups.
If neither works, start a minimal X session or use xvfb-run when you do not need the physical screen.
On a Wayland desktop, SDL 2 tries X11 first and reaches the screen through XWayland. If XWayland is not running, set SDL_VIDEODRIVER=wayland to use the native driver. That needs WAYLAND_DISPLAY and XDG_RUNTIME_DIR in the environment, which is another thing sudo and services strip.
Fix 6: hosted environments, macOS and Windows
Browser-based workspaces such as GitHub Codespaces, hosted notebooks and most online IDEs run your code in a container with no display. The options are the dummy driver for logic and tests, a VNC or noVNC desktop if the service offers one, or running the game locally. To play a Pygame game in the browser itself, look at pygbag, which packages a game for WebAssembly and needs an async main loop.
On Windows and macOS the error is rare, because the native driver is always built in. When it appears, check for an SDL_VIDEODRIVER value copied from a Linux tutorial (x11 on Windows gives “x11 not available”), and for a process started outside a desktop session, such as a service, a scheduled task or an SSH login.
Rendering without a window
The dummy driver gives you a real display surface in memory. You can draw to it, read pixels back and save it, which is enough for automated screenshot tests:
import os
os.environ["SDL_VIDEODRIVER"] = "dummy"
os.environ["SDL_AUDIODRIVER"] = "dummy"
import pygame
pygame.init()
screen = pygame.display.set_mode((320, 180))
screen.fill((20, 24, 40))
pygame.draw.circle(screen, (255, 77, 61), (160, 90), 40)
pygame.display.flip()
pygame.image.save(screen, "frame.png")
print(pygame.display.get_driver(), screen.get_at((160, 90)))
pygame.quit()
That prints dummy (255, 77, 61, 255) and writes the PNG. A plain pygame.Surface needs no display at all: you can create one, draw on it and save it without calling set_mode(). Two things do need the display module: Surface.convert() raises “cannot convert without pygame.display initialized”, and pygame.event.get() raises “video system not initialized”. For a test suite, put the two environment lines in conftest.py with os.environ.setdefault() so a developer can still override them to watch a test run.
How to confirm the fix
- Run
video_check.pyagain in the failing environment. The(default)line should name the driver you intended. - Print
pygame.display.get_driver()once at startup in the real game.offscreenordummyon a machine that should show a window is the bug. - Test through the real launcher: the systemd unit after a reboot, the container image from a clean pull, the CI job from a clean checkout.
- If Pygame itself is missing in that environment, that is a different problem: see No module named ‘pygame’. For frozen builds that die at startup, see the PyInstaller unhandled exception guide.
When a player’s machine has no usable display
Players hit this too: a Linux box with a broken session, a launcher that sets odd environment variables, a remote desktop setup. The exception is an ordinary Python one, so it can be reported. With the Pygame SDK (pip install bugnet-sdk), call bugnet_sdk.init(api_key) before pygame.display.set_mode(). Its exception hook files the traceback and flushes before Python exits, with the platform and OS version attached. To capture the environment as well, catch pygame.error around set_mode(), pass the message plus the values of SDL_VIDEODRIVER and DISPLAY to bugnet_sdk.report_error(), then re-raise. There is no screenshot, since there is no screen, and nothing is sent if the machine is offline or Python never starts. More on the hook is in sys.excepthook for Pygame.
Related guides
- How to Fix “video system not initialized” in Pygame
- How to Fix “ModuleNotFoundError: No module named ‘pygame’” in Python
- How to Fix “Failed to execute script due to unhandled exception” in a PyInstaller Pygame Build
- How to Export a Pygame Game for Linux
- Why Your Pygame Window Shows Only a Black Screen (and How to Fix It)
Frequently asked questions
What does pygame.error: No available video device mean?
SDL, the library Pygame uses for windows, tried each video driver it was built with and none could open a display. It nearly always means the process has no desktop session, as in SSH, Docker, CI or a background service, or cannot access the session that exists.
How do I run Pygame without a display?
Set the environment variable SDL_VIDEODRIVER to dummy before Pygame initialises the display, ideally before importing pygame. The display surface then lives in memory, so drawing, pixel reads and saving images work. Set SDL_AUDIODRIVER to dummy as well on machines with no sound device.
Why does my Pygame script run over SSH but no window appears?
Recent Pygame and pygame-ce wheels include an SDL offscreen driver that is used when no display is found, so set_mode succeeds silently. Print pygame.display.get_driver() to confirm. Use ssh -X, set DISPLAY to the remote desktop, or run under xvfb-run.
How do I fix pygame.error: fbcon not available or x11 not available?
That form means the SDL_VIDEODRIVER environment variable names a driver that cannot start. SDL 2 has no fbcon driver, so remove that setting. For x11, the process has no DISPLAY, cannot authenticate to the X server, or the system lacks the X client libraries.
How do I run Pygame tests in GitHub Actions or another CI system?
Either set SDL_VIDEODRIVER=dummy and SDL_AUDIODRIVER=dummy in the job environment, or run the tests under a virtual X server with xvfb-run -a python -m pytest. The dummy driver is faster. Xvfb exercises the real X11 window path.
Print pygame.display.get_driver() at startup. On current Pygame wheels a machine with no display can fall back to an invisible offscreen driver with no error, and that one line tells you where your window went.