【问题标题】:Pygame not working on Mac when calling 'pygame.display.set_mode'调用“pygame.display.set_mode”时,Pygame 无法在 Mac 上运行
【发布时间】:2014-11-27 13:29:05
【问题描述】:

我已经尝试了很长时间来解决这个问题,我什至在stackoverflow中找到了一些类似的主题,但没有任何帮助。

我正在尝试在我的 MacBook Pro OS X 10.9.4 上安装 pygame:安装本身实际上很顺利,但我在终端上输入以下行就足够了,我收到错误:

>>>import pygame

>>>pygame.init()

  (6,0)

>>>pygame.display.set_mode((640, 480))

错误如下:

* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“错误 (1000) 在第 263 行创建 CGSWindow” * 首先抛出调用栈:

(
    0   CoreFoundation                      0x00007fff929eb25c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff94491e75 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff929eb10c +[NSException raise:format:] + 204
    3   AppKit                              0x00007fff8b20ce95 _NSCreateWindowWithOpaqueShape2 + 1403
    4   AppKit                              0x00007fff8b20ba21 -[NSWindow _commonAwake] + 3720
    5   AppKit                              0x00007fff8b0e7400 -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 882
    6   AppKit                              0x00007fff8b0e6882 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1054
    7   AppKit                              0x00007fff8b0e6458 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
    8   libSDL-1.2.0.dylib                  0x0000000102a2e21e -[SDL_QuartzWindow initWithContentRect:styleMask:backing:defer:] + 279
    9   libSDL-1.2.0.dylib                  0x0000000102a2bc63 QZ_SetVideoMode + 1417
    10  libSDL-1.2.0.dylib                  0x0000000102a22f71 SDL_SetVideoMode + 906
    11  display.so                          0x0000000102a71317 set_mode + 263
    12  Python                              0x00000001000c2f7d PyEval_EvalFrameEx + 21485
    13  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
    14  Python                              0x00000001000c50b6 PyEval_EvalCode + 54
    15  Python                              0x00000001000e946c PyRun_InteractiveOneFlags + 380
    16  Python                              0x00000001000e96ce PyRun_InteractiveLoopFlags + 78
    17  Python                              0x00000001000e9ee1 PyRun_AnyFileExFlags + 161
    18  Python                              0x0000000100100bfd Py_Main + 3101
    19  Python                              0x0000000100000f14 Python + 3860
    20  ???                                 0x0000000000000001 0x0 + 1
)

libc++abi.dylib:以 NSException 类型的未捕获异常终止 中止陷阱:6

我知道它必须与 SDL 相关(我已正确安装)。 我按照类似帖子中的建议添加了该行

>>> os.environ['SDL_VIDEODRIVER']= ‘x11'

我得到同样的错误。 如果我用‘Quartz’(mac 视频驱动程序)写同一行是一样的。 我试过这个应该可以解决 SDL 问题的链接,但它没有用——> http://www.noquarterarcade.com/xcode-sdl-development-setup 和其他类似的。 我在互联网上搜索了很多,但我找不到任何与我的问题匹配的东西!我真的很希望能够在我的 Mac 上使用 pygame,而不是在我的旧 linux 计算机上! 非常感谢!

【问题讨论】:

  • 我建议尝试使用 SDL 2.x 而不是 1.x。

标签: python macos pygame


【解决方案1】:

我设法按照以下说明解决了这个问题:(适用于 OSX 的最新版本 10.9 和 10.10)

1 )创建以下内容并将其添加到 ~/.bash_profile:

# Homebrew binaries now take precedence over Apple defaults
export PATH=/usr/local/bin:$PATH

2) 安装 Apple Xcode 命令行工具: xcode-select --install

3)安装XQuartz

4) 安装自制软件: ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

5)“正确”安装 Python3 和我们从 bitbucket 安装 PyGame 所需的软件包: brew install python3 hg sdl sdl_image sdl_mixer sdl_ttf portmidi

6) 安装 PyGame: pip3 install hg+http://bitbucket.org/pygame/pygame

7)重新启动 Mac 以进行 XQuartz 更改

我发布它以防其他人有同样的问题并阅读这篇文章!希望对你有用!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 2017-06-19
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多