No module named ‘pygame‘

在尝试运行一个Python游戏程序时,遇到了Nomodulenamedpygame的错误。为了解决这个问题,已经执行了`pip3.8installpygame`命令来安装pygame库,并成功安装了版本2.4.0。现在应该能够正常运行程序了。
摘要由CSDN通过智能技术生成

项目场景:

提示:没有向对应库的提示:
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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值