python - Python程序抛出错误,因为它说它找不到pygame,即使我已经在程序中导入了它
问题描述
import sys
import pygame
def run_game():
pygame.init()
screen=pygame.display.set_mode((1200,800))
pygame.display.set_caption("Space Battle")
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.display.flip()
run_game()
我收到此错误:
回溯(最近一次通话最后):
文件“C:/Users/Dell/PycharmProjects/test/test.py”,第 3 行,
导入 pygame
ModuleNotFoundError: No module named 'pygame'
我已经安装了 pygame 并在 windows 上的 cmd 上执行了导入命令。
我该如何解决这个问题?
解决方案
如果您的电脑中有多个 python 编辑器,请确保将 pygame 安装到正确的 python 编辑器中
推荐阅读
- java - 将数据推送到堆栈上正在将内部的所有数据更改为最后推送的数据
- java - 如何在基于 Web 的实时应用程序中使用多线程,我能得到一些场景吗
- google-cloud-dataproc - 我可以通过正则表达式过滤 gcloud dataproc 集群列表吗?
- javascript - Webpack如何编译文件夹中的所有js文件并将它们移动到另一个
- c - 下面程序中的条件运算符如何改变变量b的值?
- php - WooCommerce 产品供应商如何为供应商仪表板添加菜单链接
- javascript - 将零填充到输入字段但将其延迟一秒
- c# - 统一继承
- php - OOP/PHP:是否可以为类的每个方法设置默认行为?
- php - 如何在控制台上打印错误?