Error in Pygame “Hello World” program Mac OS 10.8

萝らか妹 提交于 2019-12-11 02:21:26

问题


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()

Here is the exception:

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

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.


回答1:


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.

Have a look at pygame FAQ on how to change the video driver.



来源:https://stackoverflow.com/questions/17125292/error-in-pygame-hello-world-program-mac-os-10-8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!