我正在速成班的python书中工作,并尝试将pygame用于其中一个项目,并且python pygame和pip均已更新为最新版本,但是当我尝试运行代码时,出现错误“ ImportError:无模块名为pygame“
import sys
import pygame
def run_game():
#initialize game and create a screen object
pygame.init()
screen = pygame.display.set_mode((1200, 800))
pygame.display.set_caption("Alien Invasion")
# Start the mai loop for the game.
while True:
# Watch for keyboard and mouse events
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# Make the most recently drawn screen visible.
pygame.display.flip()
run_game()
根据我个人,此问题主要是由于系统中安装了多个python版本