Fixing “pip install pygame” errors
When pip tries to build Pygame from source, installation usually fails with long compiler errors. Here's how to recognise it and get a prebuilt package instead.
On this page
Recognise a source build#
A healthy install downloads a file ending in .whl and finishes in seconds:
Downloading pygame-2.6.1-cp313-cp313-win_amd64.whl (10.6 MB) Successfully installed pygame-2.6.1
A source build downloads a .tar.gz and then runs for a while before failing:
Downloading pygame-2.6.1.tar.gz (14.8 MB) ... Getting requirements to build wheel ... error
Messages you may see during a failing source build include sdl2-config: not found, Microsoft Visual C++ 14.0 or greater is required, metadata-generation-failed, Failed building wheel for pygame and error: subprocess-exited-with-error. The cause is nearly always the same: no prebuilt wheel exists for your Python version, operating system or processor, so pip tried to compile Pygame's C code and SDL dependencies.
Fix 1: use a Python version with wheels#
The download page lists the Python versions each package ships wheels for. If you're on a newer version, install a supported one alongside it (on Windows, the python.org installer and py -3.13 make this easy) and install Pygame with that interpreter.
Fix 2: try pygame-ce#
python -m pip uninstall pygame
python -m pip install pygame-cepygame-ce often publishes wheels for new Python versions and platforms sooner, and your code stays the same. See pygame vs pygame-ce.
Fix 3: update pip#
python -m pip install --upgrade pipOld pip versions may not recognise newer wheel tags and fall back to building.
Fix 4: build from source (advanced)#
If you really need a source build (an unusual platform, for example), install a C compiler and the SDL2 development libraries first. On Debian or Ubuntu:
sudo apt install build-essential python3-dev libsdl2-dev libsdl2-image-dev \
libsdl2-mixer-dev libsdl2-ttf-dev libfreetype6-dev libportmidi-devThen retry python -m pip install pygame. On Windows, building requires Microsoft's C++ build tools and SDL libraries; using a supported Python is far simpler.
"externally-managed-environment"#
error: externally-managed-environment × This environment is externally managed
This isn't a Pygame problem. Your operating system's Python (recent Debian, Ubuntu, Fedora, and Homebrew on macOS) refuses system-wide pip installs. Create a virtual environment:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install pygame"Could not find a version that satisfies the requirement"#
pip found no compatible release at all. Typical reasons: Python 2 or a very old Python 3, a 32-bit Python on a platform without 32-bit wheels, or pip unable to reach PyPI (offline, proxy, firewall). Check python --version and your network, then see Pygame not installing.