OS X
To install Pygame on a mac, you want to first open up the terminal. You can just open spotlight and search "terminal". It should look something like this:
First you need to decide which version of python you want to install Pygame on. Macs come with Python 2 built-in, but we'll most likely be using Python 3.
Type the following command into terminal:
pip3 install pygame
If you want to install it on Python 2 instead of Python 3, simply replace pip3 with pip. Now, we can check that it has successfully installed by pulling up Python 3 in terminal and importing Pygame like so:
python3
import pygame
If it doesn't give you any error messages, you're good to go!
Troubleshooting
Pygame imports on terminal, but doesn't work on my IDE (Pyzo, Sublime, etc.)!
You most likely have multiple versions of Python installed. That is, when you type python3 or pip3 in terminal, it might be referencing a different version of Python than your IDE uses. To test if you do, simply pull up python/python3 on terminal, and you should be able to see which version it's running:
Now, on your IDE, run your Python. Depending on your IDE, it may not show which version it's running. In either case, you can type the following to see the version you're running:
import sys
print(sys.version)
If the version on terminal and the version on your IDE doesn't match, there are two ways to fix this problem - installing it on the version of Python your IDE uses or changing which version of Python your IDE uses. Here, you should pick the choice that gets you the version of Python you want to use. If you somehow have Pygame installed on Python 3.3 but have all your other modules installed on Python 3.6, you'll probably want to stick with Python 3.6, rather than having to re-install everything on 3.3.
Install Pygame on a different version of Python
Check what version of Python your IDE uses, using the trick above. For any given version of Python 3.X, you can type into your terminal:
pip3.X install pygame
Note that you only want to keep two numbers. That is, if you Python version is 3.6.1, you only want to type "pip3.6".
Use the version of Python you installed Pygame for
If you're using an IDE and can run Python within your editor, you'll need to change which version of Python you're running. This is fairly simple if you're using Pyzo.
- In your shell window, locate the drop-down menu in your shell window. It should have a picture of a window and say Python.
- Click on the drop-down menu and select "Edit Shell Configurations"
- Under the exe menu, change the Python executable of Python to the desired version.
If that doesn't work, you can also edit your code on your editor, save, and run it with python3 on your terminal like so:
python3 FILE_NAME.py