导入 Pygame,ModuleNotFoundError:没有名为“pygame.base"的模块 [英] Importing Pygame, ModuleNotFoundError: No module named 'pygame.base'

查看:378
本文介绍了导入 Pygame,ModuleNotFoundError:没有名为“pygame.base"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导入 Pygame 模块时遇到问题.我在终端中使用以下命令安装了 pygame:

I’m having trouble importing the Pygame module. I installed pygame using the following command in the terminal:

pip install pygame 

当我输入

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'

我曾多次尝试卸载和安装 pygame.这似乎是许多人的常见问题,但我还没有找到适用于 StackOverflow/Reddit 的解决方案.

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.

我在 windows 上运行最新版本的 python (3.8.2).

I'm on windows running the latest version of python (3.8.2).

推荐答案

我假设您的计算机上安装了不止一个 python 实例.
不幸的是,当你像你一样启动 python 时,它会打开一个 psyder 的解释器当您从 CMD 使用 pip 时,它指向安装的另一个 python 实例.

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.

我建议你在你的计算机上寻找每一个 python 安装,并确保你在正确的环境中安装了这个包.

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.

为了找到每个pythonpip的安装路径,你可以使用命令where pythonwhere pip

In order to find the installation path of every python and pip you can use the command where python and where pip

尝试使用命令C:\Users\Pruthvi\AppData\Local\Microsoft\WindowsApps\python.exe -m pip install pygame

这篇关于导入 Pygame,ModuleNotFoundError:没有名为“pygame.base"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆