当前位置: 首页 > 知识库问答 >
问题:

我怎样才能让pygame在OS X大苏尔安装上访问它的模块(例如,字体,图形)?

费凯康
2023-03-14

我设法在Big Sur上安装了Pygame。但当我在其中使用模块时,它会失效。我有一台新的M1笔记本电脑,运行Big Sur(11.4),我安装了自制软件,python3,pip3,然后是Pygame。

如果我运行这个骨架:

import sys

import pygame
from pygame.locals import *

pygame.init()

fps = 60
fpsClock = pygame.time.Clock()

width, height = 640, 480
screen = pygame.display.set_mode((width, height))

is_blue = True

# Game loop.
while True:
    screen.fill((0, 0, 0))

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
            is_blue = not is_blue

    # Update.

    # Draw.
    if is_blue: color = (0, 128, 255)
    else: color = (255, 100, 0)
    pygame.draw.rect(screen, color, pygame.Rect(30, 30, 60, 60))

    pygame.display.flip()
    fpsClock.tick(fps)

它工作正常。但是如果我在init之后添加这一行:

myfont1 = pygame.font.SysFont("Comic Sans MS", 20)

我收到以下错误消息:

pygame 2.0.1 (SDL 2.0.14, Python 3.9.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
/Users/lmiratrix/PycharmProjects/pythonProject1/main_v2.py:8: RuntimeWarning: use font: cannot import name 'Font' from partially initialized module 'pygame.font' (most likely due to a circular import) (/opt/homebrew/lib/python3.9/site-packages/pygame/font.py)
(ImportError: cannot import name 'Font' from partially initialized module 'pygame.font' (most likely due to a circular import) (/opt/homebrew/lib/python3.9/site-packages/pygame/font.py))
  myfont1 = pygame.font.SysFont("Comic Sans MS", 20)
Traceback (most recent call last):
  File "/Users/lmiratrix/PycharmProjects/pythonProject1/main_v2.py", line 8, in <module>
    myfont1 = pygame.font.SysFont("Comic Sans MS", 20)
  File "/opt/homebrew/lib/python3.9/site-packages/pygame/__init__.py", line 59, in __getattr__
    raise NotImplementedError(missing_msg)
NotImplementedError: font module not available (ImportError: cannot import name 'Font' from partially initialized module 'pygame.font' (most likely due to a circular import) (/opt/homebrew/lib/python3.9/site-packages/pygame/font.py))

我不知道如何进行(我希望这不是宇宙告诉我漫画sans只是一个没有去!:-) )

背景:最初我真的很难让Pygame工作,最终在PyCharm中出现奇怪的错误信息。在发现homebrew正在安装所有的东西,包括一个新的python3,在/opt/homebrew/而不是/usr/local/bin或类似的目录中之后,我转到了terminal,但是PyCharm只在/usr/bin中找到了一点python安装。我试着卸载了Pygame然后用spotlight把电脑里各种各样的Pygame文件全部删除,重新安装了所有东西,然后登陆到这里部分成功。

共有1个答案

艾望
2023-03-14

根据这两个 github 问题(#2150、#2500),出现此问题可能有几个原因。

首先,我看到您正在运行Python 3.9.5,其中一个问题是,在某些机器上使用pygame运行较新版本的Python可能会导致问题,因此请尝试使用较旧版本的Python(如3.7或3.8)。

其次,您可能会因为pygame的不兼容问题而出现此错误。上述问题之一提到pygame与M1 Mac不兼容,我预计Big Sur安装时也会出现类似问题。在上面的一个github问题中,使用pygame 2.0.0版解决了这个问题,您可以使用pipinstallpygame==2.0.0.dev6--无缓存目录获得该版本。

错误消息还提到了循环导入,因此请确保没有多个文件相互导入。如果您仍然有错误,请查看链接的github问题以找到更多解决方案。

 类似资料:
  • 问题内容: 这是我的错误信息: 所以2.7找不到pygame。这是在新安装的python上,而且我可以进入其他模块(pyo,wx,numpy)。我已经重新安装了pygame并在相应的库文件夹中查看,但在任何地方都找不到pygame模块。重新安装不能解决此问题。有什么建议吗? 编辑:在回答问题时,我怎么安装pygame的,我从这里位于的.dmg安装http://www.pygame.org/down

  • 发生在我身上的是MDB接收消息并尝试处理它们,甚至我的服务器也没有完全启动 知道怎么解决这个问题吗?

  • 我使用Quarkus 1.10.3.final(包括quarkus-resteasy-jackson和quarkus-smallrye-openapi)和Immutables库(org.immmutables:value:2.8.8)来定义各种应用程序模型。我的问题是,大摇大摆的UI似乎不能识别标准的jackson@jsonSerialize(as=)和@jsonDeserialize(as=)注

  • 我的任务是为JMS客户机评估activemq artemis。我有RabbmitMQ的经验,但没有使用activemq artemis/JMS的经验。 我在本地机器上安装了artemis,按照说明创建了一个新的代理,并将其设置为windows服务。windows服务可以正常启动和停止。我没有对经纪人做任何改变。xml文件。 在我的第一个测试中,我试图从一个独立的java程序执行JMS队列生成/使用

  • 错误输出如下: 命令“python setup.py egg_info”失败,在/private/var/folders/6x/xsb52c7936l38mmb9f7s268m0000gn/T/pip install WFGcOd/beming/您使用的是pip版本18.1,但版本19.0.1可用。您应该考虑通过“PIP安装升级PIP”命令进行升级。

  • 我在网上搜索了一个解决方案,但没有找到。我是Node.js的新手,到目前为止,我安装的任何模块都没有任何问题。 只有从昨天当我已经搜索了一个xml模块node.js,它开始给我一个问题。 我已经更新了网络框架sdk并做了需要的事情,卸载了节点并再次安装了它,但仍然没有解决方案。 我尝试安装的模块是xml2json(npm install xml2json),错误如下: 守则: