Install Pygame on macOS

Install Python and Pygame on any Mac, Apple silicon or Intel, and avoid the system-Python and Homebrew pitfalls.

Updated
On this page

Step 1: Get Python 3#

macOS doesn't ship a Python meant for your own projects (the python3 command may only offer to install Apple's command-line developer tools). Use one of these:

  • python.org installer (simplest): download the macOS installer from python.org/downloads. It's a universal build that runs natively on Apple silicon and Intel. After installing, run the Install Certificates command found in the Python folder in Applications, so pip can verify downloads.
  • Homebrew: brew install python. Homebrew's Python blocks system-wide pip install (you'll see externally-managed-environment), so always use a virtual environment with it.

Check which Python you have in Terminal:

Terminal
python3 --version

Step 2: Create a virtual environment 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 for the community edition. Both publish wheels that work natively on Apple silicon (M-series) and Intel Macs, so no compiling is needed on supported Python versions.

Step 3: Check it works#

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

Remember to run source .venv/bin/activate in each new Terminal window before running your game, or point your editor at .venv/bin/python.

Common macOS problems#

ProblemFix
error: externally-managed-environmentYou're using Homebrew's Python without a virtual environment. Create and activate one as above.
command not found: pipUse python3 -m pip, or activate your virtual environment.
SSL certificate errors during installRun "Install Certificates.command" from the python.org Python folder in Applications.
pip starts compiling and failsYour Python version has no prebuilt Pygame wheel yet. Use a supported Python or pygame-ce. See compatibility.
The window opens behind other windows or the Dock icon bouncesClick the Python icon in the Dock; this is normal for scripts started from Terminal.
↑ ↓ to moveEnter to openEsc to close