-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pygame_sdl2.font ImportError when running programs frozen with PyInstaller #94
Comments
I'm not much of a windows expert, but I'd suggest using something like https://docs.microsoft.com/en-us/sysinternals/downloads/procmon to see what it's accessing when it crashes. |
I had a poke around with procmon but concluded after a lot of staring at lists of event that it probably wasn't a .dll issue. Further investigation confirms this. Digging into it further with good old trial and error, taking imports into and out of my test programs I've narrowed the remaining issue (assuming you handle the minor json import problem) down to importing pygame_sdl2.font failing in a frozen program, if you also import pygame.transform - that's from the regular version of pygame. Which doesn't sound like too much of a bother, except it turns out that pyTMX (the best library for importing TMX files from the Tiled editor) always imports pygame.transform. I'm also slightly concerned because I currently have no idea why this happens. I can get programs to run in frozen mode with pygame_sdl2.font and without pygame.transform, and visa versa. It could be some general issue with the font module conflicting with other libraries that may crop up elsewhere, or it could be just related to pygame.transform. I'd be curious to know if this happens when freezing on other platforms. Here's the test program I'm using on python 3.6: https://gist.github.com/MyreMylar/a0c945cc6782f06d138930c1395e154e And here's the spec file for PyInstaller: https://gist.github.com/MyreMylar/7a8a97e4d181fe914aaa44733fe0f127 I'll probably hammer at it a bit further, you never know when new inspiration will strike, but if anybody has any good ideas about this problem I'd love to hear them. |
You can try pygame_sdl2.import_as_pygame(), which will override the pygame imports with their pygame_sdl2 equivalents. I don't support mixing the two in the same process, and since I don't use it, I don't support PyInstaller myself. |
I had a go with My feeling, after a couple more tests, is that this might be a problem of too many dlls rather than too few. I suspect that some of the SDL1 era dlls that pygame uses are incompatible with pygame_sdl2's SDL2 era versions, and that somehow by loading up the SDL1 versions at all your program will crash. Anyway, assuming my read on the situation is accurate that doesn't sound like a solveable problem for pygame_sdl2's code. Probably worth documenting at some point though that Specific to my particular program (and for anyone else who has the exact same issue) I'm pursuing getting a pygame dependency removed from PyTMX here. Skipping back to the top post again. I'll try and submit a pull request later (once I unwind some of my testing) for the json library import issue, which I think will just be adding Apologies for all the blather, but hopefully it helps somebody else sometime in the future. |
I ran into the same pygame_sdl2.font ImportError as described in the original post.
So there is definitely an issue related to the .dll for managing pygame_sdl2.font After lots of digging and head-banging, I managed to trace the root cause to this .dll file: It turns out that when PyInstaller does its magic, it is grabbing that .dll file from pygame and sticking it into the EXE's root directory. And that is what is used when the EXE launches. Unfortunately, the libfreetype-6.dll packaged with pygame_sdl2 is not the same! PyInstaller grabs that .dll also, but sticks it in a pygame_sdl2 subfolder in the EXE... and as far as I can tell, that is never accessed! And the pygame version of this .dll is not compatible with pygame_sdl2. Solution: Note: I have tried unsuccessfully thus far to force PyInstaller to grab the correct pygame_sdl2 version of this .dll file at the outset by adjusting settings in the .spec file. So I am left with this manual fix every time I compile the EXE. If I find an automated solution via PyInstaller .spec file, I will post that later. |
I've spent some time poking at making a usable windows .exe file of my pygame_sdl2 project with PyInstaller. After a fair bit of fiddling around and learning the ropes I've found two issues so far:
The
json
library, is not included automatically by PyInstaller. I assume this is related to the way it is being dynamically imported somewhere in pygame_sdl2. Luckily it has a fairly easy fix in that you can just 'import json' in your own code and it will be included in your frozen distribution. It would be nice to make pygame_sdl2 handle this itself though.pygame_sdl2.font
fails to import at runtime after freezing. Googling around seems to suggest this can come from a missing .dll file, but I'm at a loss as to exactly what that could be as the error helpfully gives no specifics. I have the obvious SDL_ttf.dll and SDL2_ttf.dll in there. In case it helps here is a screenshot of all the dlls PyInstaller scoops up into it's distribution directory:Of course it could be something else related to the font module and not dlls causing the import error.
However, if you remove all traces of pygame_sdl2 font from your application it appears to build and run fine. So we are so close to functional here!
The text was updated successfully, but these errors were encountered: