Pygame is a cross-platform Python module that allows you to develop video games. It has inbuilt computer graphics and audios that make easy development of the games. To use it you have to install it on your system. Many programmers are not able to install pygame module in their system and get the no module named pygame error.
In this entire tutorial, you will know how to solve the ModuleNotFound: no module named ‘pygame’ error.
Why do you get the ModulNotFound Error?
The modulenotfound error generally comes when you had not properly installed that python package in your system. Most of the cases are solved by just installing the package in the system.
Root Cause of no module named ‘pygame’ error
The main or root cause for getting this modulenotfound error is that you have not installed pygame in your system. And another reason is your python interpreter has not known the path of the package installed.
You will get the red underline below the package name if you try to import pygame package in pycharm.
Solution of ModuleNotFoundErro: no module named ‘pygame’ error
The solution for this no module named pygame error is very simple. You have to install it in the system using the pip command.
But before that, you have to also check the version of the python. To check it open your command prompt or terminal and write the below command.
The prompt or terminal will show the python version. If it is python 3. xx then use the pip3 command and if it is python 2. xx then use the pip command.
I have already checked the version of python for my system and it is python 3. xx. Therefore I will use the pip3 command.
Run the following bash command to install the pygame package.
pip3 install pygame
After the installation, if you again import the package then you will not see the red underline and also no module named pygame error in pycharm.
Pygame allows you to develop video games using the python language. There are also many other programming languages to develop video games. However, if you know knowledge of python is above good then go for it.
The above method will solve the error if you are getting no module named pygame.