PyInstaller packaging is system-dependent. On Windows, it creates an .exe executable; on Linux, it outputs an ELF binary. Cross-platform packaging isn’t supported.
Installation
Install via pip:
| |
Package as a Single File
Use the --onefile argument:
| |
Common Arguments
For packaging Windows applications, common arguments include:
--windowed: Hides the console window (if you’re implementing a GUI).--icon=icon.ico: Adds an icon to the application.--hidden-import: Explicitly specifies required dependencies (prevents automatic analysis from missing them).--add-data: Adds extra resource files to the package.--debug: Enables debug information.
Package as Multiple Files
When packaging as multiple files, use the --onedir argument:
| |
Dependency files end up in the _internal folder, which isn’t ideal.
Only PyInstaller versions 6.1.0 and above can use this argument:
| |
This way, dependencies and the entry point are in the same directory.
Packaging Configuration Items
Suppose your project’s configuration is at project/conf/settings.json.
If you want to include this file when packaging, first package it as multiple files:
| |
This generates a my_program.spec file in your current directory. Modify the data in a to input the files you want to package as a tuple, like this:
| |
Then, delete all files in the dist/ folder and run the command (or don’t delete, just confirm when prompted):
| |
Project
Using this method, the software from https://blog.yexca.net/archives/211 is now packaged into an executable! (Though error handling is still missing.)