首页 > 解决方案 > 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 上执行了导入命令。

我该如何解决这个问题?

标签: pythonpython-3.ximportpygame

解决方案


如果您的电脑中有多个 python 编辑器,请确保将 pygame 安装到正确的 python 编辑器中


推荐阅读