Install Pygame on macOS
Install Python and Pygame on any Mac, Apple silicon or Intel, and avoid the system-Python and Homebrew pitfalls.
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-widepip install(you'll seeexternally-managed-environment), so always use a virtual environment with it.
Check which Python you have in Terminal:
Terminal
python3 --versionStep 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 pygameor 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.aliensRemember 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#
| Problem | Fix |
|---|---|
error: externally-managed-environment | You're using Homebrew's Python without a virtual environment. Create and activate one as above. |
command not found: pip | Use python3 -m pip, or activate your virtual environment. |
| SSL certificate errors during install | Run "Install Certificates.command" from the python.org Python folder in Applications. |
| pip starts compiling and fails | Your 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 bounces | Click the Python icon in the Dock; this is normal for scripts started from Terminal. |