尝试安装pygame

1 投票
1 回答
512 浏览
提问于 2025-04-17 13:47

我在我的 sys.path 末尾添加了这个路径:C:\\Python27\\lib\\site-packages\\pygame

当我运行以下代码时:

import pygame, sys
from pygame.locals import *

pygame.init()
DISPLAYSURF = pygame.display.set_mode((400,300))
pygame.display.set_caption('Hello World!')
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        pygame.display.update()

我遇到了一个错误:ImportError: No module named locals。不过我可以在 C:\Python27\lib\site-packages\pygame\ANYFOLDER 这个地方运行这个 .py 文件,没有任何错误。

另外,如果可以的话,我想在 Netbeans 中使用这个路径。我已经在 Netbeans 的 Python 平台管理器中添加了这个路径,但我还是遇到了和之前一样的错误。

我到底漏掉了什么或者做错了什么呢?

1 个回答

1

提问者自己的解决方案:

好的,我发现我不能把我的文件命名为pygame.py,不然它会试图导入自己(?)。

在Netbeans中也是一样。绝对不能有任何东西(项目、文件夹等)叫做“pygame”。

撰写回答