Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pygame error: "ImportError: No module named 'pygame'"

This is my situation:

enter image description here

I tried importing pygame in both python 3.4.2 and python 3.6.3 using both pip and pip3 respectively.

In the python 3.4.2 shell:

Traceback (most recent call last) is:
File "", line 1, in
import pygame
ImportError: No module named 'pygame'

In the python 3.6.3 shell:

Traceback (most recent call last):
File "", line 1, in
import pygame
File "C:\Users\aditya dand\AppData\Local\Programs\Python\Python36\lib\site-packages\pygame__init__.py", line 141, in from pygame.base import *
ModuleNotFoundError: No module named 'pygame.base'

Those are the errors that occurred.

I also used pygame-1.9.2a0-hg_5974ff8dae3c%2B.win32-py3.4.msi.
It's showing the header's file of pygame, but it's not importing something.

What can I do to solve this?

like image 250
Aditya Dand Avatar asked Jun 29 '18 18:06

Aditya Dand


People also ask

How do I fix No module named pygame?

The Python "ModuleNotFoundError: No module named 'pygame'" occurs when we forget to install the pygame module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install pygame command.


1 Answers

Step1:

check http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame to find a Windows installer that matches the version of Python you're running. The current version of pygame is : pygame-1.9.4-cp37-cp37m-win_amd64.whl

Move this file to the folder C:\Users\username\AppData\Local\Programs\Python\Python37\Scripts

=========================================

Step2:

open cmdand then type:

cd\
cd /d C:\Windows
cd /d C:\Users\username\AppData\Local\Programs\Python\Python37\Scripts

and then type the command:

pip install pygame

Now you have successfully installed pygame package.

=========================================

Step3:

open PyCharm File >> setting make sure the "Project Interpreter" has the "pygame" package like the following:

File>>Setting>> make sure the "pygame" package is there.

like image 97
kimmi Avatar answered Oct 22 '22 21:10

kimmi