No module named ‘pygame‘

项目场景:

提示:没有向对应库的提示:
Traceback (most recent call last):
File “py_Game.py”, line 1, in
import pygame
ModuleNotFoundError: No module named ‘pygame’


问题描述

python执行后没办法运行

import pygame

# 初始化pygame
pygame.init()

# 设置窗口大小
screen = pygame.display.set_mode((640, 480))

# 设置窗口标题
pygame.display.set_caption("My Game")

# 游戏主循环
running = True
while running:
    # 处理事件
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # 更新游戏状态

    # 绘制游戏画面
    screen.fill((0, 0, 0)) # 使用黑色填充背景
    pygame.display.flip() # 更新屏幕

# 退出pygame
pygame.quit()


原因分析:

提示:没有对应的pygame库:执行
命令完毕 D:\softwere\python\Python38\Scripts\pip3.8.exe install pygame
D:>D:\softwere\python\Python38\Scripts\pip3.8.exe install pygame
Collecting pygame
Downloading pygame-2.4.0-cp38-cp38-win_amd64.whl (10.6 MB)
---------------------------------------- 10.6/10.6 MB 2.2 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.4.0


你可能感兴趣的:(pygame,python,开发语言)