Install Pygame on Linux

Install Pygame with pip in a virtual environment on any distribution, or use your package manager, and understand why "externally-managed-environment" appears.

Updated
On this page

This works on every distribution and gives you the latest Pygame. First make sure Python's venv module is available:

Terminal
# Debian, Ubuntu, Linux Mint
sudo apt install python3-venv python3-pip
# Fedora
sudo dnf install python3-pip
# Arch Linux
sudo pacman -S python-pip

Then create an environment for your project and install Pygame:

Terminal
mkdir my-game && cd my-game
python3 -m venv .venv
source .venv/bin/activate
python -m pip install pygame        # or: python -m pip install pygame-ce

Prebuilt wheels exist for x86_64 and 64-bit ARM (aarch64, including Raspberry Pi OS 64-bit), so pip doesn't need a compiler on supported Python versions.

Why "externally-managed-environment"?#

Recent Debian, Ubuntu, Fedora and other distributions mark their system Python as managed by the package manager (PEP 668). Running pip install pygame outside a virtual environment then stops with error: externally-managed-environment, to protect system tools that depend on Python. Use a virtual environment as above. Avoid --break-system-packages on your main system.

Alternative: the distribution package#

Most distributions package Pygame, which is convenient for quick scripts that use the system Python:

Terminal
sudo apt install python3-pygame     # Debian, Ubuntu
sudo dnf install python3-pygame     # Fedora
sudo pacman -S python-pygame        # Arch Linux

Distribution packages can lag behind the latest release. Don't mix a distribution package and a pip install in the same Python.

Check it works#

Terminal
python -c "import pygame; print(pygame.version.ver)"
python -m pygame.examples.aliens

Common Linux problems#

ProblemFix
externally-managed-environmentUse a virtual environment (see above).
No module named venv / ensurepip is not availableInstall python3-venv (Debian/Ubuntu).
pip compiles and fails with sdl2-config: not foundNo wheel for your Python or CPU. Use a supported Python, or install SDL2 development packages (libsdl2-dev, libsdl2-image-dev, libsdl2-mixer-dev, libsdl2-ttf-dev, libfreetype6-dev on Debian/Ubuntu) and retry.
No sound, or mixer not initializedSee no sound in Pygame.
Running under WSL on WindowsWSL2 on Windows 11 can show windows through WSLg; on older setups run Pygame directly on Windows instead.
↑ ↓ to moveEnter to openEsc to close