问题描述
我在 Mountain Lion 中运行 Pygame.我认为这一切都安装正确,因为我可以毫无错误地导入模块.
I am running Pygame in Mountain Lion. I think it is all installed correctly as I can import the module without any errors.
当我尝试运行一个非常简单的程序时,出现异常.代码如下:
When I try and run a very simple program I get an exception. Here is the code:
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 有关,但我不太了解,无法修复它.
I think it's the pygame.display.set_mode((400, 300)) that is causing it. My Googling tells me it's something graphical, possibly to do with SDL, but I don't understand enough to be able to fix it.
推荐答案
可能是 SDL 视频驱动程序没有正确初始化.首先确保 pygame.init()
返回 (6,0)
.这应该告诉您是否一切都已正确初始化.如果没有,您可以使用 pygame.display.get_driver()
检查它正在使用的视频驱动程序.如果它没有为您的机器使用正确的驱动程序,您可以通过将环境变量 os.environ['SDL_VIDEODRIVER']=
设置为以下 x11、dga、fbcon 之一来更改它、directfb、ggi、vgl、svgalib、aalib
(来自 pygame 文档),取决于可用的驱动程序.
It may be that the SDL video driver is not initialized properly. First make sure pygame.init()
returns (6,0)
. This should tell you if everything is initialized properly. If not, you can check what video driver it is using pygame.display.get_driver()
. If it is not using the right driver for your machine, you can change it by setting the environment variable os.environ['SDL_VIDEODRIVER']=
to one of the following x11, dga, fbcon, directfb, ggi, vgl, svgalib, aalib
(from pygame documentation), depending on the drivers available.
在 如何更改视频驱动程序.
这篇关于Pygame“Hello World"中的错误程序 Mac OS 10.8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!