【问题标题】:Pygame: Font module not availablePygame:字体模块不可用
【发布时间】:2013-07-23 08:00:15
【问题描述】:

在 OS X 上运行 Python 2.7.2 和 Pygame 1.9.2pre。

另一个令人讨厌的问题:初始化 pygame.font 模块会产生一个我不敢的错误......好吧,尝试自己解决。我猜这是一个相当普遍的 pygame 相关问题......但我一直无法找到任何解决方案。

import pygame
pygame.init()

pygame.font.init()

给予:

Desktop/font.py:4: RuntimeWarning: use font: dlopen(/Library/Python/2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/X11/lib/libfreetype.6.dylib
  Referenced from: /Library/Frameworks/SDL_ttf.framework/Versions/A/SDL_ttf
  Reason: image not found
(ImportError: dlopen(/Library/Python/2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/X11/lib/libfreetype.6.dylib
  Referenced from: /Library/Frameworks/SDL_ttf.framework/Versions/A/SDL_ttf
  Reason: image not found)
  pygame.font.init()
Traceback (most recent call last):
  File "Desktop/font.py", line 4, in <module>
    pygame.font.init()
  File "/Library/Python/2.7/site-packages/pygame/__init__.py", line 70, in __getattr__
    raise NotImplementedError(MissingPygameModule)
NotImplementedError: font module not available
(ImportError: dlopen(/Library/Python/2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/X11/lib/libfreetype.6.dylib
  Referenced from: /Library/Frameworks/SDL_ttf.framework/Versions/A/SDL_ttf
  Reason: image not found)

这里到底出了什么问题?字体模块不可用的一些可能原因是什么?常见原因?常见修复?

如果有人能告诉我哪里出了问题,即使它不能解决问题,我也会很感激! 非常感谢!

编辑:我正在使用 64 位版本的 Python 和 32 位 Pygame。 (似乎没有适用于 Mac OS 的 64 位 Pygame)

【问题讨论】:

  • 为什么需要font.init?这个方法是由pygame.init()自动调用的,所以如果它通过了pygame.init()这行代码,你应该可以安全使用pygame字体
  • 在从文件加载字体之前这不是必要的吗? font = pygame.font.Font(none, 24) 给出了类似的错误。
  • 试试这个看看会发生什么:myFont = pygame.font.SysFont("Times New Roman" 30)(没有pygame.font.init()
  • 嗯...也许它在pygame.init() 中处理,但为什么在font.init() 处理时不会产生错误?
  • 我不确定。这很奇怪,但如果字体在不使用该语句的情况下工作,则无需担心。

标签: python fonts module pygame


【解决方案1】:

(自我回答)

问题:在 64 位 Python 中使用 32 位 Pygame 通常不是一个好主意。

解决方案:始终在 64 位架构中使用 Python 和 Pygame。 (或 32 个)。

附注目前似乎没有适用于 OS X 的 64 位 Pygame,因此您必须使用 32 位 Python。

P.S.S(安装 32 位 Python 后,您可能需要重新安装 32 位 Pygame 才能生效。这就是发生在我身上的事情)

【讨论】:

  • 在 64 位 ubuntu 16 上,安装 sudo apt-get install libsdl-ttf2.0-0 并通过 conda install -c cogsci pygame 安装 pygame
【解决方案2】:

我遇到了同样的问题,制作这个问题的进度如下:

  1. 我从http://www.pygame.org/ 下载pygame 源文件
  2. 我使用命令python setup.py install 安装pygame

然后,我可以import pygame并正常使用基本的pygame功能,但是如果我尝试导入其他相关模块如import pygame.font,它会跳出font module not found错误。我尝试通过手动安装一些缺失的模块来解决这个问题as suggested here:

$ sudo apt-get install python-dev libsdl-image1.2-dev libsdl-mixer1.2-dev  
libsdl-ttf2.0-dev   libsdl1.2-dev libsmpeg-dev python-numpy subversion 
libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev

但是,这个问题仍然存在。

最后,我意识到这是一个依赖问题,所以我通过命令sudo python setup.py clean 删除了已安装的pygame,并删除了python/site-packages 中的所有文件。我通过命令重新安装pygame

sudo apt-get install python-pygame

一切正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多