Using --onefile with a .spec in PyInstaller

Viewed 62712

I'm "compiling" a program using PyInstaller using a .spec file. I'm using the .spec file because I need to include an extra file in the program. When I try to do PyInstaller --onefile Prog.spec, it still makes a folder in dist with all the files separate instead of making a single file as I'd expect. If I do PyInstaller --onefile Prog.py then it does make a single .exe file in dist, which is what I want. Is there something special I need to do when using a .spec file?

2 Answers

You can add the extra file on the command line instead of editing the spec file:

pyinstaller --onefile --add-data <SRC;DEST or SRC:DEST> yourfile.py

Otherwise, make sure in the spec file there is no collect step:

"In one-file mode, there is no call to COLLECT, and the EXE instance receives all of the scripts, modules and binaries."

https://pyinstaller.readthedocs.io/en/stable/usage.html for more info on command line flags.

This also may offer some insight if problems persist: Bundling data files with PyInstaller (--onefile)

Related