Compile Python 3.6 script to standalone exe with Nuitka on Windows 10
In your buildscript.py
file
use --onefile
instead of --standalone
All the files will still be created but you don't need them and you can delete them.
Easier than Nuitka for a single executable is e.g. PyInstaller:
pyinstaller --onefile program.py
(to disable the console window for GUI applications add the -w
option).
To create a single executable with Nuitka, you can create a SFX archive from the generated files. You can run Nuitka with the --standalone
option which generates a program_dist
directory.
Create then a 7-Zip SFX config file config.txt
:
;!@Install@!UTF-8!
GUIMode="2"
ExecuteFile="%%T/program_dist/program.exe"
;!@InstallEnd@!
Then get the 7-Zip SFX from https://github.com/chrislake/7zsfxmm (from releases – 7zsd_extra_171_3901.7z
) and unpack the 7zsd_All_x64.sfx
file.
Pack then the program_dist
with 7-Zip (so the folder is included in the archive) to program.7z.
Then, an SFX can be created with copy /b 7zsd_All_x64.sfx + config.txt + program.7z single_executable.exe
.
On Unix, you can also create yourself an SFX if you create a tar archive and append it to a shell script which extract it and unpack it, for details see https://www.linuxjournal.com/node/1005818.