Menu

How to Install Pygame with pip (pygame-ce)

Install pygame with one pip command on Windows, macOS or Linux, check that it works, and fix the errors people hit most: pip not found, No module named pygame, and the wrong Python.

This page includes runnable editors. Edit, run, and see output instantly.

Pygame is installed with pip, Python's package installer. You need Python 3 first: if python3 --version (or py --version on Windows) prints nothing useful, install Python and come back.

Install with one command

Open a terminal (Command Prompt or PowerShell on Windows, Terminal on macOS and Linux) and run the line for your system:

# Windows
py -m pip install pygame-ce

# macOS and Linux
python3 -m pip install pygame-ce

That installs pygame-ce, the community edition of pygame. You still write import pygame. If you would rather have the original package, use pip install pygame instead, but never install both: they share the pygame name and overwrite each other. Pygame vs pygame-ce explains the difference.

Writing python3 -m pip instead of plain pip matters. It installs pygame for exactly the Python that python3 starts, which is the one that will run your game.

Check that it works

python3 -c "import pygame; print(pygame.version.ver)"
pygame-ce 2.5.7 (SDL 2.32.10, Python 3.12.12)
2.5.7

The first line is pygame's greeting, printed whenever it is imported; the second is the version. To see a real game, run one of the examples that ship with pygame:

python3 -m pygame.examples.aliens

Then save this program as main.py and run it with python3 main.py. It is the same program you can play here: it draws a ball that bounces off the walls.

If a window opens with a moving ball, pygame is installed. Close the window to end the program.

Install in a virtual environment

For a real project, give the game its own virtual environment, so its packages do not mix with other projects:

python3 -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
python -m pip install pygame-ce

While the environment is active, python main.py runs your game with that environment's pygame.

Fixing install problems

ModuleNotFoundError: No module named 'pygame'. pygame went to a different Python than the one running the script. Install it with that Python (python3 -m pip install pygame-ce), and in VS Code or PyCharm select the same interpreter in the editor's Python settings.

pip is not recognized, or command not found. Use python3 -m pip (or py -m pip on Windows) instead of pip. On Windows, if py is missing too, reinstall Python with "Add python.exe to PATH" ticked.

pip tries to build pygame from source and fails. pip found no ready-made package (a wheel) for your Python version, usually because the Python is very new or very old. Upgrade pip with python3 -m pip install --upgrade pip and try again, or use a Python version that pygame-ce lists on its PyPI page.

error: externally-managed-environment on Linux or Homebrew Python. Your system Python does not let pip install into it. Create a virtual environment as shown above and install there.

Both pygame and pygame-ce are installed. Remove both and install one: python3 -m pip uninstall pygame pygame-ce, then python3 -m pip install pygame-ce.

Without installing anything

Every example in these docs runs in your browser on pygame-ce, so you can learn the library before setting anything up. For your own programs, the pygame playground has a full editor and game window. When you are ready, open your first pygame program.

Frequently Asked Questions

How do I install pygame?

Open a terminal and run python3 -m pip install pygame-ce (on Windows, py -m pip install pygame-ce). Then check it with python3 -c "import pygame; print(pygame.version.ver)".

Should I install pygame or pygame-ce?

Either works for learning, and the code is the same: both are imported with import pygame. pygame-ce is updated more often and has more features, so it is the better default. Install only one of them.

Why does it say No module named pygame after I installed it?

pip installed it for a different Python than the one running your script. Install with the same Python you run: python3 -m pip install pygame-ce, and in an editor such as VS Code or PyCharm pick that interpreter.

How do I check which pygame version I have?

Run python3 -c "import pygame; print(pygame.version.ver)". When pygame is imported it also prints a line such as pygame-ce 2.5.7 (SDL 2.32.10, Python 3.12.12).

Coddy programming languages illustration

Learn to code with Coddy

Get started