Reputation: 85
I’m having trouble importing the Pygame module. I installed pygame using the following command in the terminal:
pip install pygame
When I enter
import pygame
and run the script, I get the following error:
Traceback (most recent call last):
File "C:\Users\Pruthvi\.spyder-py3\temp.py", line 1, in <module>
import pygame
File "C:\Users\Pruthvi\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pygame\__init__.py", line 130, in <module>
from pygame.base import *
ModuleNotFoundError: No module named 'pygame.base'
I have tried uninstalling and installing pygame many times. This seems to be a common problem amongst many, yet I haven't found a solution that works on StackOverflow/Reddit.
I'm on windows running the latest version of python (3.8.2).
Upvotes: 0
Views: 3670
Reputation: 568
I had this issue before, what fixed it for me was
first uninstalling pygame, with pip uninstall pygame
then reinstalling it, with pip install pygame
Upvotes: 0
Reputation: 614
I assume you have more than one instance of python installed on your computer.
and unfortunately when you start python like you did it opens an interpreter of psyder
and when you use pip from the CMD it points to another instance of python installed.
I suggest you to look for every installation of python on you computer and make sure you are installing the package within the right environment.
In order to find the installation path of every python
and pip
you can use the command where python
and where pip
Try installing pygame by using the command C:\Users\Pruthvi\AppData\Local\Microsoft\WindowsApps\python.exe -m pip install pygame
Upvotes: 1
Reputation: 13061
You can check this file exist or not.
C:\Users\Pruthvi\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pygame\base.cp38-win_amd64.pyd
If not, you will got message, ModuleNotFoundError: No module named 'pygame.base'
And you should reinstall pygame with option --no-cache-dir
Upvotes: 0