0

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).

Pruthvi Amin
  • 75
  • 2
  • 10
  • **Try my MACOS SOLUTION:** https://stackoverflow.com/questions/40224385/pygame-no-module-called-pygame-base/65183915#65183915 – victorkolis Dec 07 '20 at 14:59

4 Answers4

1

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

Mogi
  • 596
  • 1
  • 6
  • 18
  • Hi, the where python command returns the following C:\Users\Pruthvi\AppData\Local\Microsoft\WindowsApps\python.exe. I installed pygame in C:\Users\Pruthvi\AppData\Local\Programs\Python\Python38-32\Lib\site-packages which is where I've installed all of my packages so far and have had no problems? – Pruthvi Amin Jun 13 '20 at 19:04
0

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

Jason Yang
  • 11,284
  • 2
  • 9
  • 23
  • Hi, I reinstalled using **pip install pygame --no-cache-dir**, but the same error occurred?Also, instead of **pygame\base.cp38-win_amd64.pyd** I have **pygame\base.cp38-win32.pyd** – Pruthvi Amin Jun 13 '20 at 19:28
  • You have pygame\base.cp38-win32.pyd, but base not found. Maybe it's version issue. Use pip install pygame --no-cache-dir or pip install xxxxxxxx.whl, You can download wheel here [pygame wheel](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame), select correct version for your python 3.8 and windows 32-bit: pygame‑1.9.6‑cp38‑cp38‑win32.whl – Jason Yang Jun 14 '20 at 13:28
0

I had this issue before, what fixed it for me was

  1. first uninstalling pygame, with pip uninstall pygame

  2. then reinstalling it, with pip install pygame

Anonymous
  • 528
  • 3
  • 17
0

That fixes it for me on python3.8, upgraded my pygame 1.9.4 to 1.9.6

Nick
  • 97
  • 10