The Invent with Python Blog

Writings from the author of Automate the Boring Stuff.

How to Install Pygame on Windows, macOS, and Linux

Fri 27 January 2023    Al Sweigart

If you know how to run pip (Python's package installer) from a terminal window, run:

pip install pygame

If you don't know how to use pip in the terminal, then you can install in Python's interactive shell (or REPL) by running:

import subprocess, sys;[sys.executable, '-m', 'pip', 'install', 'pygame'])

(This is the way pipfromrepl installs Python packages from the interactive shell.)

This process works on Windows, macOS, and Linux for Python versions 3.6 to 3.10. Note that as of January 2023, the Pygame maintainers haven't updated Pygame to work on Python 3.11 or 3.12. However, there is a .whl "wheel" file available to install Pygame on Python 3.11 on Windows. Either run this from a Command Prompt or Windows Terminal window:

pip install

Or run this from the interactive shell:

import subprocess, sys;[sys.executable, '-m', 'pip', 'install', ''])

You can test to see if Pygame was installed successfully by importing it from the interactive shell. If no error message appears, the installation was successful:

>>> import pygame

This blog post will be updated as new versions of Python and Pygame are made available.

Learn to program for free with my books for beginners:

Sign up for my "Automate the Boring Stuff with Python" online course with this discount link.

Email | Mastodon | Twitter | Twitch | YouTube | GitHub | Blog | Patreon | LinkedIn | Personal Site