1. Environment
Windows
2. Installation
Prepare file: PyWin32 or Pypiwin32
Run the following installation command: pip install Pyinstaller
3. Packaging
Copy. py or. pyw files to the directory where Pyinstaller resides
Execute command: pyinstaller-f xxx.py , the generated file will be automatically placed in the Dist directory, the file name defaults to Xxx.exe.
Common parameter Description:
-F: Package all the files into one. exe.
-D: Package all files into a directory containing executables and other files as required.
-N Name: renames the executable file.
-W: Open the packaged program and the command-line window will not pop up.
4. Individual file and directory comparisons
The directory is larger than the size of a single file;
The directory is faster to open than a single file.
Package on WIN7, put on XP, directory open failed , single file normal.
Detailed parameter description See document
http://pythonhosted.org/PyInstaller/#general-options
General Options
-h, --help |
Show this help message and exit |
-v, --version |
Show Program version info and exit. |
--distpath=DIR |
Where to put the bundled app (default:./dist) |
--workpath=WORKPATH |
|
Where to put all the temporary work files,. log,. Pyz and etc. (default:./build) |
-y, --noconfirm |
|
Replace Output directory (default:specpath/dist/specname) without asking for confirmation |
--upx-dir=UPX_DIR |
|
Path to UPX utility (Default:search the execution path) |
-a, --ascii |
Do not include Unicode encoding support (default:included if available) |
--clean |
Clean Pyinstaller cache and remove temporary files before building. |
--log-level=LOGLEVEL |
|
Amount of detail in build-time console messages (Default:info, choose one of DEBUG, INFO, WARN, ERROR, CRITICAL) |
What to generate
-F, --onefile |
Create a one-file bundled executable. |
-D, --onedir |
Create a One-folder bundle containing an executable (default) |
--specpath=DIR |
Folder to store the generated spec file (default:current directory) |
-n NAME, --name=NAME |
|
Name to assign to the bundled app and spec file (Default:first script ' s basename) |
What to bundle, where to search
-p DIR, --paths=DIR |
|
A path to search for imports (like using PYTHONPATH). Multiple paths is allowed, separated by ': ', or use this option multiple times |
--hidden-import=MODULENAME |
|
Name an import isn't visible in the code of the script (s). This option can be used multiple times. |
--additional-hooks-dir=HOOKSPATH |
|
An additional path to search for hooks. This option can be used multiple times. |
--runtime-hook=RUNTIME_HOOKS |
|
Path to a custom runtime hook file. A Runtime hook is code which is bundled with the executable and was executed before any other code or module to set up Speci Al features of the runtime environment. This option can be used multiple times. |
--exclude-module=EXCLUDES |
|
Optional Module or package (his Python names,not path names), that'll be ignored (as Thoughit is not found). This option can be used multiple times. |
--key=KEY |
The key used to encrypt Python bytecode. |
How to Generate
-d, --debug |
Tell the bootloader-issue progress messages while initializing and starting the bundled app. used to diagnose problems With missing imports. |
-s, --strip |
Apply a symbol-table strip to the executable and GKFX Libs (not recommended for Windows) |
--noupx |
UPX even if it is available (works differently between Windows and *nix) |
Windows and Mac OS X specific options
-c, --console, --nowindowed |
|
Open a console window for standard I/O (default) |
-w, --windowed, --noconsole |
|
Windows and Mac OS x:do not provide a console window for standard I/O. On Mac OS X the also triggers building an OS x. app bundle. This option was ignored in *nix systems. |
-i <FILE.ico or FILE.exe,ID or FILE.icns>, --icon=<FILE.ico or FILE.exe,ID or FILE.icns> |
|
FILE.ico:apply. Icon to a Windows executable. File.exe,id, extract the icon with ID from an EXE. FILE.icns:apply the icon to the. App bundle on Mac OS X |
Windows Specific Options
--version-file=FILE |
|
Add a version resource from FILE to the EXE |
-m <FILE or XML>, --manifest=<FILE or XML> |
|
Add manifest FILE or XML to the EXE |
-r <FILE[,TYPE[,NAME[,LANGUAGE]]]>, --resource=<FILE[,TYPE[,NAME[,LANGUAGE]]]> |
|
ADD or update a resource of the given type, name and language from FILE to a Windows executable. File can is a data file or an exe/dll. For data files, at least TYPE and NAME must is specified. LANGUAGE defaults to 0 or may is specified as wildcard * To update all resources of the given TYPE and NAME. For exe/dll files, all resources from FILE would be added/updated to the final executable if TYPE, NAME and LANGUAGE is OM itted or specified as wildcard *. This option can be used multiple times. |
--uac-admin |
Using This option creates a Manifest which would request elevation upon application restart. |
--uac-uiaccess |
Using This option allows a elevated application to work with Remote Desktop. |
Windows side-by-side Assembly searching options (Advanced)
--win-private-assemblies |
|
any Shared assemblies bundled into the Application'll is changed into Private assemblies. This means the exact versions of these assemblies would always is used, and any newer versions installed on user machines a T the system level would be ignored. |
--win-no-prefer-redirects /td> |
|
while searching for GKFX or Private assemblies to bundles into the applicat Ion, Pyinstaller would prefer not to follow policies that redirect to newer versions, and would try to bundle the exact vers Ions of the assembly. |
Python program packaged as an. exe----Pyinstaller tool