我在 Mountain Lion 中运行 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()
这是一个例外:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating CGSWindow on line 259'
First throw call stack:
(
0 CoreFoundation 0x00007fff89699b06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff83b433f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff896998dc +[NSException raise:format:] + 204
3 AppKit 0x00007fff85492b49 _NSCreateWindowWithOpaqueShape2 + 655
4 AppKit 0x00007fff85491340 -[NSWindow _commonAwake] + 2002
5 AppKit 0x00007fff8544fd82 -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 1763
6 AppKit 0x00007fff8544eecf -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1568
7 AppKit 0x00007fff8544e89f -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
8 libSDL-1.2.0.dylib 0x00000001043cbaf9 -[SDL_QuartzWindow initWithContentRect:styleMask:backing:defer:] + 279
9 libSDL-1.2.0.dylib 0x00000001043c951b QZ_SetVideoMode + 1409
10 libSDL-1.2.0.dylib 0x00000001043c0809 SDL_SetVideoMode + 907
11 display.so 0x000000010444330f set_mode + 271
12 Python 0x00000001040be754 PyEval_EvalFrameEx + 7873
13 Python 0x00000001040bc769 PyEval_EvalCodeEx + 1638
14 Python 0x00000001040bc0fd PyEval_EvalCode + 54
15 Python 0x00000001040dae88 run_mod + 53
16 Python 0x00000001040daf2f PyRun_FileExFlags + 137
17 Python 0x00000001040daa7d PyRun_SimpleFileExFlags + 718
18 Python 0x00000001040eb593 Py_Main + 3039
19 libdyld.dylib 0x00007fff862497e1 start + 0
)
libc++abi.dylib: terminate called throwing an exception
我认为这是导致它的 pygame.display.set_mode((400, 300)) 。我的谷歌搜索告诉我这是图形化的,可能与 SDL 有关,但我理解的不够多,无法修复它。