I made a game, and it has several external files that I'd like to compile with the .py file to a single .exe, but Pyinstaller won't do it. It always returns a FileNotFoundError
.
I've tried both ways of bundling:
1. Directly on the terminal (on both cmd and Anaconda Prompt) using the --add-data
option
pyinstaller --onefile -w --add-data="arrow keys.png;." --add-data="background.png;." --add-data="background.wav;." --add-data="bullet.png;." --add-data="enemy.png;." --add-data="esc.png;." --add-data="explosion.wav;." --add-data="laser.wav;." --add-data="player.png;." --add-data="Retro Gaming.ttf;." --add-data="spacebar.png;." --add-data="ufo.png;." main.py
2. Modifying the .spec file
added_files = [
('arrow keys.png', '.'),
('background.png', '.'),
('background.wav', '.'),
('bullet.png', '.'),
('enemy.png', '.'),
('esc.png', '.'),
('explosion.wav', '.'),
('laser.wav', '.'),
('player.png', '.'),
('Retro Gaming.ttf', '.'),
('spacebar.png', '.'),
('ufo.png', '.')
]
a = Analysis(
['main.py'],
pathex=[],
binaries=[],
datas=added_files,
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
Either way, whenever I run the .exe, be it by clicking it or via terminal, it opens this window:
It's not an issue with the ufo.png
file either. I've modified my code to not need it and the error remains. It happens with that file because it's the first external file called by the code.