Installing Python 3, PyGame and PyOpenGL on Mac OS X El Capitan

I needed to get set up for a project recently that used PyGame and PyOpenGL, running on top of Python 3. I'm running El Capitan currently and in the past I've had extreme difficulty getting a PyGame setup working (on Mavericks), so I was pleased to find it was a flawless setup process on El Capitan (thanks go to the Homebrew contributors for streamlining it so well).

These instructions (largely based on this page) assume you've already got Homebrew installed, with Homebrew git.

$ brew cask install xquartz

$ brew install python3

$ pip3 install --upgrade pip setuptools

$ brew install python

$ pip install --upgrade pip setuptools

$ brew linkapps python3

$ brew linkapps python

$ brew install sdl sdl_image sdl_ttf portmidi libogg libvorbis

$ brew install sdl_mixer --with-libvorbis

$ brew tap homebrew/headonly

$ brew install smpeg

$ brew install mercurial

$ pip3 install hg+http://bitbucket.org/pygame/pygame

$ pip3 install pygame

$ pip3 install pyopengl

Now you've got a working PyGame setup (don't forget to run your script using python3).