Pygame is an open-source, cross-platform Python module used for designing and scripting video games. It can be a fantastic tool to use on devices like the Raspberry Pi.
I initially tried using pip to install Pygame on Fedora, but that didn't work. Instead, the most reliable way to get it running is through Fedora's official package repository.
Finding and Installing the Pygame Package
A quick repository search confirms that Pygame is packaged as a Python 3 module:
[darryl@linuxbox ~]$ dnf search pygame
Last metadata expiration check: 0:10:16 ago on Mon 18 May 2020 11:02:17 PM EDT.
====================== Name & Summary Matched: pygame =======================
pygame-devel.i686 : Files needed for developing programs which use pygame
pygame-devel.x86_64 : Files needed for developing programs which use pygame
=========================== Name Matched: pygame ============================
python3-pygame.x86_64 : Python3 modules for writing games
[darryl@linuxbox ~]$
To install the module, run the following command:
sudo dnf install python3-pygame
Here are the dependencies that dnf will resolve, download, and install:
[darryl@linuxbox ~]$ sudo dnf install python3-pygame
Last metadata expiration check: 0:05:52 ago on Mon 18 May 2020 11:08:33 PM EDT.
Dependencies resolved.
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
python3-pygame x86_64 1.9.6-7.fc32 fedora 2.9 M
Installing dependencies:
SDL x86_64 1.2.15-43.fc32 fedora 213 k
SDL_image x86_64 1.2.12-23.fc32 fedora 44 k
SDL_mixer x86_64 1.2.12-19.fc32 fedora 95 k
SDL_ttf x86_64 2.0.11-17.fc32 fedora 25 k
fluidsynth x86_64 1.1.11-7.fc32 fedora 25 k
fluidsynth-libs x86_64 1.1.11-7.fc32 fedora 209 k
gnu-free-fonts-common noarch 20120503-22.fc32 fedora 122 k
gnu-free-sans-fonts noarch 20120503-22.fc32 fedora 782 k
jack-audio-connection-kit x86_64 1.9.14-2.fc32 fedora 534 k
libffado x86_64 2.4.1-10.fc32 fedora 901 k
libgfortran x86_64 10.1.1-1.fc32 updates 823 k
libmikmod x86_64 3.3.11.1-8.fc32 fedora 154 k
libquadmath x86_64 10.1.1-1.fc32 updates 197 k
libxml++ x86_64 2.40.1-10.fc32 fedora 103 k
openblas x86_64 0.3.9-2.fc32 fedora 30 k
openblas-threads x86_64 0.3.9-2.fc32 fedora 4.5 M
portmidi x86_64 217-32.fc32 fedora 31 k
Installing weak dependencies:
python3-numpy x86_64 1:1.18.4-2.fc32 updates 4.4 M
Transaction Summary
=============================================================================
Install 19 Packages
Total download size: 16 M
Installed size: 78 M
Is this ok [y/N]:
Verifying the Installation
Once the installation is complete, you can check that everything is working correctly by opening the Python shell and importing the module:
[darryl@linuxbox ~]$ python3
Python 3.8.2 (default, Feb 28 2020, 00:00:00)
[GCC 10.0.1 20200216 (Red Hat 10.0.1-0.8)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
>>>
If the installation was successful, you will see the community greeting and version number shown above.
Related Resources
Done! Now you can start coding games with the Pygame module. I would love to see what you develop.
Happy coding!