'What modification to my spec file accomplishes the same thing as adding the command line option --onefile when using pyinstaller?
I have a simple script, hello_world.py, and want to create a Windows 10 executable with the aid of Pyinstaller. I'm using Python 3.9, on a Mac (11.6.1) with a Windows 10 virtual machine along with the most recent version of Pyinstaller.
Of course, the simplest way to create the .exe as a single file is to type pyinstaller hello_world.py --onefile at the command line. This produces a folder, dist, which contains just the .exe itself.
However, for my more complicated application, I'll need to include many datas and hidden imports, which I do by modifying the spec file produced by typing pyinstaller hello_world and edit accordingly. Here's a simple example of a modified spec file for hello_world.py:
block_cipher = None
data=[('Desktop/my_image.png', '.')]
a = Analysis(['hello_world.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[networkx],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='hello_world',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='hello_world')
This is the spec file produced by first typing pyinstaller hello_world.py at the command line and then editing the resulting spec file by adding an image to the data and a single hidden import. (I chose networkx, not that it matters.)
Now typing pyinstaller produces a dist folder which contains another folder, hello_world as opposed to a dist folder containing just hello_world.exe. This isn't what I want.
I realize I can include other options at the command line to add data and hidden imports, but my actual application contains so many of these things that it's more efficient to work with the spec file.
So the ultimate question is what modification to my spec file achieves the same outcome as adding the --onefile option at the command line?
Solution 1:[1]
Thanks to the assistance of E.Fahlgren on the Pyinstaller"s Google Mailing list, I learned that the problem is resolved if one deletes coll and adds exclude_binaries=False to exe.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | fishbacp |
