Pygame 错误:'pygame' 没有属性 'init' [英] Pygame error: 'pygame' has no attribute 'init'
问题描述
我刚刚下载了 Pygame,但遇到了一个错误:AttributeError: module 'pygame' has no attribute 'init'.我在stackoverflow上环顾四周,有人通过重命名文件来修复错误(我不知道该怎么做).目录如下
I just downloaded Pygame but is running into an error: AttributeError: module 'pygame' has no attribute 'init'. I was looking around on stackoverflow and someone fixed the error by renaming the files (which I don't know how to do). The directory is the following
Python -> Lib -> site-packages ->pygame
Python -> Lib -> site-packages ->pygame
让我困惑的部分是在 pygame 文件夹中
The confusing part for me is inside the pygame folder
pygame > Include, Lib
Include > pygame > (many hh files)
Lib > SitePackages > pygame > init (I know that it has the attribute init)
既然有 '3' pygame 文件夹,这是否会导致我的程序出错?
Since there is '3' pygame folder, is this causing the error for my program?
import pygame, sys
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello World!')
while True: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
推荐答案
只需将您的文件从 pygame.py
重命名为 myTestGame.py
例如,因为您正在导入使用 import pygame
Just rename your file from pygame.py
to myTestGame.py
for example because you're importing the same file when you use import pygame
这篇关于Pygame 错误:'pygame' 没有属性 'init'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!