Pygame font not working after py2exe

2019-08-02 00:39发布

问题:

I have this code that works fine when I convert it to an .exe with py2exe, except when it tries to load text on the screen. It comes up with the error:

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.)

Based on some other research, I have come to the conclusion that my problem has to do with some .dll files. The two SysFonts that I am using are 'monospace' and 'Arial'.

Can Anyone please explain a fix to this problem it detail?

回答1:

I have the same problem,the reason is that py2exe regards the SDL_ttf.dll file as a system owned dll and excludes it from the distribution package. You can add this code on your 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

also you can vist http://thadeusb.com/weblog/2009/4/15/pygame_font_and_py2exe for more infomation