简体   繁体   中英

Importing Pygame, ModuleNotFoundError: No module named 'pygame.base'

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

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM