leafleafleafDocy banner shape 01Docy banner shape 02Man illustrationFlower illustration

Python Pygame installation tutorial

Estimated reading: 2 minutes 54 views

Earlier, we learned to program using turtle drawing. However, the turtle module is relatively slow and cannot be used to draw large numbers of animations or moving objects. In this tutorial, we will install and use a new module, Pygame, which also provides functionality for creating games with a Graphical User Interface (GUI). It allows us to draw graphics, animate and even create arcade-style games using the knowledge and skills we have learned so far.

Installing Pygame requires the pip tool. pip is a tool for installing and managing Python packages. When we install Python3.7, pip will also be installed automatically, no need to install it separately.

We can see this file in the Python installation directory. For example, my Python is installed in the C:\Users\li.qiang\AppData\Local\Programs\Python directory, then the pip tool is installed in C:\Users\li.qiang\AppData\Local\Programs\Python\ Python37-32\Scripts directory, as shown in Figure 1.

Python Pygame pip
figure 1
You can also enter pip directly in the command line window to check whether the pip tool is installed. If installed, the corresponding command prompt message will appear, as shown in Figure 2.

Python Pygame installation
figure 2

With the pip tool, we can consider installing Pygame. The official website of Pygame is http://www.pygame.org, as shown in Figure 3. On this website, we can see an introduction to Pygame and instructions on how to install it.

Python Pygame installation instructions
image 3
From the introduction on the official website, we can know that we can execute the installation command directly from the command line. In the case of confirming that the Internet is connected, enter “python -m pip install -U pygame –user” on the command line, and press the Enter key to install, as shown in Figure 4.

Python Pygame to install
Figure 4
Then you only need to wait until the installation progress reaches 100%, and it prompts that the installation of Pygame is successful. You can see that the current version of Pygame is 1.9.6, as shown in Figure 5.

Python Pygame installed successfully
Figure 5
 At this time, if you enter import pygame in the Python Shell, the current version of Pygame will be displayed, as shown in Figure 6.

Python Pygame version

Leave a Comment

CONTENTS