How to install Pygame Zero on macOS

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.

It’s not hard, in theory, to install it. It is distributed through pip, using

pip install pgzero

But I had troubles with my Mac. It failed during the installation withat

fatal error: 'SDL.h' file not found
#include "SDL.h"
         ^~~~~~~
1 error generated.

I checked what could be the problem, and I found a possible version requirement mismatch, maybe it’s a recent problem due to new releases of the libraries, but I had to install the latest version directly from GitHub, using:

pip install git+https://github.com/lordmauve/pgzero@master

Then it worked fine!

Download my free Python Handbook!

⭐️ Join the waiting list for the JavaScript Masterclass ⭐️