Pygame字体在py2exe之后无法正常工作

时间:2014-02-15 16:20:56

标签: python python-2.7 pygame py2exe

我有这个代码,当我用py2exe将它转换为.exe时,它可以正常工作,除非它试图在屏幕上加载文本。它出现了错误:

C:\Users\Slinky\Desktop\dist\FlappyBat.exe:120: RuntimeWarning: use font: DLL load failed:                   The specified module could not be found.
(ImportError: DLL load failed: The specified module could not be found.)
Traceback (most recent call last):
File "FlappyBat.py", line 176, in <module>
File "FlappyBat.py", line 120, in main
File "pygame\__init__.pyc", line 70, in __getattr__
NotImplementedError: font module not available
(ImportError: DLL load failed: The specified module could not be found.)

基于其他一些研究,我得出结论,我的问题与一些.dll文件有关。我使用的两个SysFonts是'monospace'和'Arial'。

任何人都可以详细解释这个问题的解决方法吗?

1 个答案:

答案 0 :(得分:0)

我有同样的问题,原因是py2exe将SDL_ttf.dll文件视为系统拥有的dll并将其从分发包中排除。 您可以在setup.py

上添加此代码
origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
       if os.path.basename(pathname).lower() in ["sdl_ttf.dll"]:
               return 0
       return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL

您也可以访问http://thadeusb.com/weblog/2009/4/15/pygame_font_and_py2exe以获取更多信息