Mac Mojave 上的 Pygame [英] Pygame on Mac Mojave

查看:39
本文介绍了Mac Mojave 上的 Pygame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Python 3.7.2、Pyenv 和 Pygame 1.9.4 设置了一个开发环境.执行 python 文件时, python3 ./main.py 我得到一个空白的 Pygame 屏幕.见下图:

<块引用>

许多其他帖子表明 Pygame 尚不能与 macOS Mojave 配合使用.我不确定我是否相信.

我的项目中的代码如下所示:

导入pygame白色 = (255, 255, 255)红色 = (255, 0, 0)pygame.init()大小 = (700, 500)屏幕 = pygame.display.set_mode(size)pygame.display.set_caption('我的游戏')完成 = 错误时钟 = pygame.time.Clock()虽然没有完成:对于 pygame.event.get() 中的事件:如果 event.type == pygame.QUIT:完成 = 真屏幕填充(白色)pygame.draw.rect(屏幕,红色,[20, 20, 250, 100], 2)pygame.display.flip()时钟滴答(60)pygame.quit()

<块引用>

为了验证不是我的代码失败,我运行: python3 -m pygame.examples.aliens 这会打开一个空白窗口并播放音乐.

有没有人有幸在他们的计算机上使用此功能

解决方案

我的 macbook Pro (2015) 在最新的操作系统 (mojave) 上遇到了同样的问题.当我按照这个 github 问题的说明操作时,它工作正常:

https://github.com/pygame/pygame/issues/555(感谢@ChaseHardin)

似乎是 SDL、黑暗模式(莫哈韦沙漠)、brew 和 python 的问题.
你必须运行:

brew uninstall --force python3

https://www.python.org/downloads 上手动安装 python/release/python-372/-> 选择 python x 64 macos 安装程序.

pip3 安装pygame

您的屏幕将是红色的.(我的是绿色的,我从来没有这么高兴看到我生命中丑陋的绿色).

I've setup a development environment using Python 3.7.2, Pyenv, and Pygame 1.9.4. When executing the python file, python3 ./main.py I get a blank Pygame screen. See picture below:

Many other posts suggest that Pygame does not yet work with the macOS Mojave. I'm not sure I believe that.

The code in my project looks like the following:

import pygame

WHITE = (255, 255, 255)
RED = (255, 0, 0)

pygame.init()

size = (700, 500)
screen = pygame.display.set_mode(size)

pygame.display.set_caption('My Game')

done = False

clock = pygame.time.Clock()

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

        screen.fill(WHITE)

        pygame.draw.rect(screen, RED, [20, 20, 250, 100], 2)

        pygame.display.flip()

        clock.tick(60)
pygame.quit()

To verify that it was not my code failing, I ran: python3 -m pygame.examples.aliens which opens a blank window and plays music.

Has anyone had luck getting this to work on their computer

解决方案

I had the same problem on my macbook Pro (2015) on latest OS (mojave). It works fine when I followed the instruction on this github issue:

https://github.com/pygame/pygame/issues/555 (Thanks @ChaseHardin)

It seems to be a problem with SDL, dark mode (mojave), brew and python.
You have to run:

brew uninstall --force python3

Install python by hand on https://www.python.org/downloads/release/python-372/ -> Choose python x 64 macos installer.

pip3 install pygame

Your screen will be red. (mine was green, i never be so happy to see ugly green in my life).

这篇关于Mac Mojave 上的 Pygame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆