In this article we want to learn How to Install Pygame in Linux & Windows.
What is Pygame ?
Pygame is free and open source library for creating games and multimedia applications using Python programming language. it provides functionalities for creating games such as creating and handling images, animations, sound effects and musics. it also provides an event based framework for input handling (keyboard, mouse and joystick events) and support for various game related tasks like collisions, game logic and game physics.
Pygame is designed to be simple and easy to use and it is great choice for beginners who want to create 2D games without having to learn complex game development concepts. with Pygame you can create different types of games, from simple arcade games to more advanced games with nice graphics and sound effects.
How to Install Pygame in Linux & Windows ?
Installing Pygame in Linux:
- Open terminal.
- Type following command to install the Pygame library:
1 |
pip install pygame |
- Wait for the installation process to complete.
- And also you can verify the installation by below command.
1 |
python -m pygame.examples.aliens |
Installing Pygame in Windows:
- Download latest version of Pygame from their official website (https://www.pygame.org/download.shtml).
- Open command prompt.
- Type following command to install Pygame:
1 |
pip install pygame-1.9.6-cp38-cp38-win_amd64.whl |
- Replace “pygame-1.9.6-cp38-cp38-win_amd64.whl” with the name of the Pygame wheel file you downloaded.
- Wait for the installation process to complete.
- And also you can verify the installation by below command.
1 |
python -m pygame.examples.aliens |
Also you can install Pygame in Windows with pip command like this:
1 |
pip install pygame |
This is simple example of how to create a window using Pygame:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import pygame # Initialize Pygame pygame.init() # Set the window size window_size = (400, 300) # Create the window screen = pygame.display.set_mode(window_size) # Run the game loop running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Update the screen pygame.display.update() # Quit Pygame pygame.quit() |
This code creates window with size of 400 x 300 pixels. the game loop checks for the QUIT event, which is generated when the user closes the window, and sets the runing flag to False to exit the loop and quit the game. update function is called to update the screen with any changes made in the game loop.
Run the code and this will be the result.

Learn More on Python
- Python Best Libraries for Web Development
- How to Make an Instagram Bot
- How to send Message to Instagram with Python
- Build Python REST API with FastAPI
- Python Best Frameworks for Web Development
- Why to Use Python for Web Development
- How to Install TKinter in Windows and Linux