Reputation: 967
I used pyinstaller --add-data "icon.png;." --add-data "casino.png;." debug2.py
which works fine but when I make a single file using pyinstaller --onefile --add-data "icon.png;." --add-data "casino.png;." debug2.py
the executable no longer works.
I believe this is an issue with relative paths maybe?
Here is my python code for loading these assets:
icon = pygame.image.load('icon.png')
image_path="casino.png",
What can I do to get this working?
Upvotes: 0
Views: 383
Reputation: 967
The code was fine on the pyinstaller end but when using --onefile the assets are unpacked in a temporary file so the python code was looking in the wrong directory.
To fix it I had to add
try:
wd = sys._MEIPASS
except AttributeError:
wd = os.getcwd()
icon_path = os.path.join(wd,"icon.png")
casino_path = os.path.join(wd,"casino.png")
Then change my paths for icon & casino to:
icon = pygame.image.load(icon_path)
image_path=casino_path,
Upvotes: 1