How to install Pygame Zero on macOS
By Flavio Copes
Learn how to install Pygame Zero on macOS with a Python venv and pip, and what to try if the SDL headers are missing during the build.
A few months ago I bought a book from Raspberry Pi Press called Code the Classics. It’s an awesome book that talks about some classic games, including Sensible Soccer and Centipede, and then proceeds to creating a clone of those games with Python. It’s a total of 5 games.
That’s a very nice book, you can download it for free at the link I provided above and you can find the code of the games built in the book on GitHub at https://github.com/Wireframe-Magazine/Code-the-Classics.
The book does not actually explain how to build those games, unfortunately. It just lists the source code.
Anyway, it’s a great way to start your Python game development adventure.
I finally found some time to dive into, and the first step was to install Pygame Zero, a library to create games on top of Pygame.
On modern macOS, install it in a virtual environment. Create one, activate it, then install from PyPI:
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install pgzero
That pulls the current stable release from PyPI (1.2.1 as of this update).
If the install fails while building and you see something like:
fatal error: 'SDL.h' file not found
#include "SDL.h"
^~~~~~~
1 error generated.
install the SDL2 headers with Homebrew, then retry the pip install:
brew install sdl2 sdl2_image sdl2_mixer sdl2_ttf
python3 -m pip install pgzero
You should not need to install from GitHub master for a normal setup. Stick to the PyPI package unless you are deliberately chasing an unreleased fix.
Want me to talk about your product? You can sponsor this site.
Related posts about python: