Download and Install Pygame in Python

In this tutorial we will show you how to download, install and setup the Pygame Library in Python.


Installing Pygame in Python

The most universal method of installing pygame is through the use of pip. It’s a package installer for Python commonly used for installing python libraries. It usually comes bundled with Python (atleast on Windows) so you don’t need to get it separately.

pip install pygame

Run the above command in the terminal/command prompt and the library will download and install itself. If this command doesn’t work, its most likely because you don’t have Python added in PATH.

To fix this you will have to use the terminal to navigate to the folder where your Python installation is, then execute the command again. If you add Python to PATH, then it won’t matter where you execute this command from.

If you have pip3 installed (as is common on newer versions of Linux and macOS), then use the following command:

pip3 install pygame

Installing Pygame in Linux

If you need to install Pygame on a Linux/Ubuntu family OS and you don’t have pip, you can use the following command:

sudo apt-get install python3-pygame

The pip commands from earlier will also work on Linux/Mac as long as you have it installed.

To check if you have pip installed on Linux, run the following command:

pip --version

It’s possible you might not have pip, but you might have pip3 so check for that if the above doesn’t work.

pip3 --version

Check Pygame Installation

You can do two things to verify that Pygame was downloaded and installed successfully.

First you can check the version of your pygame installation. If this command works, then pygame was successfully installed.

pip show pygame 

Remember to use this in the terminal, not in a Python Program. It should show you details about the pygame installation (e.g. version number, location, etc.)

Alternatively, another simple approach is to execute a python program with the following code.

import pygame

If it imports without any errors, then Pygame has installed successfully.

To learn more about pygame and how to use it, refer to our main page for pygame, where we give you an overview of all the important concepts required to create games in Pygame.


This marks the end of the Download and Install Pygame in Python Tutorial. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the tutorial content can be asked in the comments section below.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments