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

别说谁变了你拦得住时间么 提交于 2021-01-07 01:35:35

问题


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


回答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




回答2:


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




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/62364309/importing-pygame-modulenotfounderror-no-module-named-pygame-base

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!