Installing Pygame

Tags: python pygame tutorial

Making games is a great way to improve your programming skills while making something fun at the same time. Pygame is a set of tools for Python that make it easy to work with graphics and sound.

Unfortunately, installing Pygame is not as easy as using it is. Below you’ll find the best directions we’ve found for getting it working on your system. Follow the directions below, and let us know in the comments below if you have any problems.

Installing Pygame for OS X

Note: For most of these instructions you will need to use the command line. Don’t be intimidated - programmers work on the command line all the time. Once you get used to it, you’ll find it’s the quickest and easiest way to do lots of useful things on the computer.

You access the command line by running the Terminal application - click on the Spotlight icon and type “terminal” to find it.

Step 1: Install XCode command line tools

XCode is the tool from Apple for creating Mac and iOS applications. It can be installed from the App Store (it’s free). When it’s finished, type the following at the command line:

$ xcode-select --install

Step 2: Install Homebrew (http://brew.sh)

Homebrew is a tool to easily install all kinds of software from the command line. It saves you having to go to a bunch of different sites and download lots of individual installers. Copy and paste this on the command line:

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

and follow the directions. You’ll also need to install Homebrew Cask (http://caskroom.io):

$ brew install caskroom/cask/brew-cask

Step 3: Install the rest of the software

Now we can start installing all the requirements for Pygame. Just type the following commands one at a time and let the computer do its thing:

$ brew cask install xquartz

$ brew install python3

$ brew install python

$ brew linkapps python3

$ brew linkapps python


$ brew install git

$ 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

Step 4: See if it works!

Now we can see if it works. Run Python from the command line:

$ python3

and try loading Pygame:

>>> import pygame

If you don’t see an error message, you’re all set! Now head over to our YouTube Channel and start coding!

Important

You will not be able to use Pygame from IDLE. You will need to run your programs from the command line like this:

$ python3 mygame.py

Some code editors will also let you run Python programs from inside the program, but we’ll talk about that in a separate post.

Installing Pygame for Windows

Step 1: Install Python

If you haven’t already, go to http://python.org/ and download the latest Python installer. Click on “Downloads” and choose “Download Python 3.5.0” (or whatever the latest version is).

When the download finishes, choose “run” - you may need to open your Downloads folder and double-click on the installer file.

Check the box labeled “Add Python 3.5 to PATH” and then click “Customize Installation”. Under “Optional Features” make sure all the boxes are checked. Under “Advanced Options” you can leave it as-is. Then click the Install button and let the computer complete the process.

Step 2: Install Pygame for Windows

Click here and download the appropriate installer for your computer. For most people, this will be the latest 32-bit installer, for example:

pygame‑1.9.2a0‑cp35‑none‑win32.whl

Choose “Save” and let the file download.

Now, you need to go to the command line. In your Start Menu search for “command” and you’ll see a button for “Command Prompt”.

Type the following:

C:\Users\name\> cd Downloads
C:\Users\name\Downloads> pip install pygame-1.9.2a0-cp35-none-win32.whl

Step3: See if it works!

Now we can see if it works. Run Python from the command line:

C:\Users\name\Downloads> python

and try loading Pygame:

>>> import pygame

If you don’t see an error message, you’re all set! Now head over to our YouTube Channel and start coding!

Comments