PyInstaller(1)
pyinstaller π bundle a Python app and every single dependency into one little package β¨
okay bestie, sit down, hydrate, because this one is a whole journey π«Ά. pyinstaller takes your Python application, grabs all of its dependencies, and squishes them into a single package. iconic behaviour, honestly.
πΈ DESCRIPTION πΈ
here's the whole vibe of how you call it:
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME]
[--contents-directory CONTENTS_DIRECTORY] [--add-data SOURCE:DEST]
[--add-binary SOURCE:DEST] [-p DIR] [--hidden-import MODULENAME]
[--collect-submodules MODULENAME] [--collect-data MODULENAME]
[--collect-binaries MODULENAME] [--collect-all MODULENAME]
[--copy-metadata PACKAGENAME] [--recursive-copy-metadata PACKAGENAME]
[--additional-hooks-dir HOOKSPATH] [--runtime-hook RUNTIME_HOOKS]
[--exclude-module EXCLUDES] [--splash IMAGE_FILE] [-d
{all,imports,bootloader,noarchive}] [--optimize LEVEL] [--python-option
PYTHON_OPTION] [-s] [--noupx] [--upx-exclude FILE] [-c] [-w]
[--hide-console {minimize-early,hide-late,minimize-late,hide-early}] [-i
<FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">]
[--disable-windowed-traceback] [--version-file FILE] [--manifest <FILE
or XML>] [-m <FILE or XML>] [-r RESOURCE] [--uac-admin] [--uac-uiaccess]
[--argv-emulation] [--osx-bundle-identifier BUNDLE_IDENTIFIER]
[--target-architecture ARCH] [--codesign-identity IDENTITY]
[--osx-entitlements-file FILENAME] [--runtime-tmpdir PATH]
[--bootloader-ignore-signals] [--distpath DIR] [--workpath WORKPATH]
[-y] [--upx-dir UPX_DIR] [--clean] [--log-level LEVEL] scriptname
[scriptname ...]
likeβ¦ look at all those flags. she's thriving. π
π― positional arguments π―
scriptnameβ the name(s) of the scriptfile(s) you want processed, or exactly one.specfile. heads up: if you hand over a.specfile, most of the options below are unnecessary and just get ignored. this one is required, no skipping it bestie. (required)
βοΈ options βοΈ
-h,--helpβ shows you this help message and dips. bye! π-v,--versionβ shows the program version info and exits.--distpath DIRβ where the bundled app goes to live. (default:./dist)--workpath WORKPATHβ where all the temporary work files go β your.log,.pyz, and etc. (default:./build)-y,--noconfirmβ replaces the output directory (default:SPECPATH/dist/SPECNAME) without asking you for confirmation first. no vibe check, just sends it. π₯--upx-dir UPX_DIRβ path to the UPX utility. (default: search the execution path)--cleanβ cleans the PyInstaller cache and removes temporary files before building. little pre-game reset, love that for her. π§Ό--log-level LEVELβ how much detail you get in the build-time console messages. LEVEL can be one ofTRACE,DEBUG,INFO,WARN,DEPRECATION,ERROR,FATAL(default:INFO). it's also settable via thePYI_LOG_LEVELenvironment variable, and this option overrides that env var. π
π What to generate: π
-D,--onedirβ creates a one-folder bundle that contains an executable. this is the default, she's the main character. π-F,--onefileβ creates a one-file bundled executable. just one lil file. precious.--specpath DIRβ the folder where the generated spec file gets stored. (default: current directory)-n NAME,--name NAMEβ the name you assign to the bundled app and the spec file. (default: the first script's basename)--contents-directory CONTENTS_DIRECTORYβ for onedir builds only, bb. this sets the name of the directory where all the supporting files go β and by "supporting files" we mean literally everything except the executable itself. want the old onedir layout with no contents directory at all? pass"."and it's like the contents directory never happened. πͺ
π¦ What to bundle, where to search: π¦
--add-data SOURCE:DESTβ extra data files (or whole directories full of data files) to add to the application. the argument value should look like"source:dest_dir", where source is the path to the file (or directory) being collected, and dest_dir is the destination directory relative to the top-level application directory. the two paths are separated by a colon (:). wanna drop a file straight into the top-level application directory? use.as the dest_dir. this option can be used multiple times. π--add-binary SOURCE:DESTβ extra binary files to add to the executable. peep the--add-dataoption for the format, it's the same deal. this option can be used multiple times.-p DIR,--paths DIRβ a path to search for imports (basically like usingPYTHONPATH). multiple paths are allowed, separated by':', or you can just use this option multiple times. equivalent to supplying thepathexargument in the spec file. π¦--hidden-import MODULENAME,--hiddenimport MODULENAMEβ names an import that isn't visible in the code of the script(s). sneaky little import, we see you π. this option can be used multiple times.--collect-submodules MODULENAMEβ collects all submodules from the specified package or module. this option can be used multiple times.--collect-data MODULENAME,--collect-datas MODULENAMEβ collects all data from the specified package or module. this option can be used multiple times.--collect-binaries MODULENAMEβ collects all binaries from the specified package or module. this option can be used multiple times.--collect-all MODULENAMEβ collects all submodules, data files, and binaries from the specified package or module. the full set, the whole package, the entire meal. π½οΈ this option can be used multiple times.--copy-metadata PACKAGENAMEβ copies metadata for the specified package. this option can be used multiple times.--recursive-copy-metadata PACKAGENAMEβ copies metadata for the specified package and all of its dependencies. she brings her whole friend group. 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 that gets bundled with the executable and runs before any other code or module, to set up special features of the runtime environment. first in line, always. this option can be used multiple times.--exclude-module EXCLUDESβ an optional module or package (and bestie, that's the Python name, not the path name) that will be ignored, as though it was never found in the first place. ghosted. π» this option can be used multiple times.--splash IMAGE_FILEβ (EXPERIMENTAL) adds a splash screen with the image IMAGE_FILE to the application. the splash screen can display progress updates while unpacking. cute and informative. β¨
π οΈ How to generate: π οΈ
-d {all,imports,bootloader,noarchive},--debug {all,imports,bootloader,noarchive}β gives you a hand with debugging a frozen application. this argument may be provided multiple times to select several of the following options:all: all three of the following options.imports: specifies the-voption to the underlying Python interpreter, which makes it print a message each time a module is initialized, showing the place (filename or built-in module) from which it's loaded. see https://docs.python.org/3/using/cmdline.html#id4.bootloader: tells the bootloader to issue progress messages while initializing and starting the bundled app. used to diagnose problems with missing imports.noarchive: instead of storing all frozen Python source files as an archive inside the resulting executable, stores them as files in the resulting output directory.
--optimize LEVELβ the bytecode optimization level used for collected python modules and scripts. for details, see the section "Bytecode Optimization Level" in the PyInstaller manual. π--python-option PYTHON_OPTIONβ specifies a command-line option to pass to the Python interpreter at runtime. currently supports"v"(equivalent to"--debug imports"),"u","W <warning control>","X <xoption>", and"hash_seed=<value>". for details, see the section "Specifying Python Interpreter Options" in the PyInstaller manual.-s,--stripβ applies a symbol-table strip to the executable and shared libs. not recommended for Windows, so likeβ¦ read the room. π«--noupxβ do not use UPX even if it's available. heads up: this works differently between Windows and *nix.--upx-exclude FILEβ prevents a binary from being compressed when using upx. typically used when upx corrupts certain binaries during compression (rude of it, honestly). FILE is the filename of the binary without the path. this option can be used multiple times.
πͺ Windows and Mac OS X specific options: π
-c,--console,--nowindowedβ opens a console window for standard i/o. this is the default. on Windows, this option has no effect if the first script is a.pywfile.-w,--windowed,--noconsoleβ Windows and Mac OS X: do not provide a console window for standard i/o. on Mac OS this also triggers building a Mac OS.appbundle. on Windows this option is automatically set if the first script is a.pywfile. this option is ignored on *NIX systems. π§--hide-console {minimize-early,hide-late,minimize-late,hide-early}β Windows only: in a console-enabled executable, this has the bootloader automatically hide or minimize the console window if the program owns the console window (i.e., it was not launched from an existing console window).-i <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">,--icon <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">β let's break it down, bestie:FILE.ico: applies the icon to a Windows executable.FILE.exe,ID: extracts the icon with ID from an exe.FILE.icns: applies the icon to the.appbundle on Mac OS.- if you enter an image file that isn't in the platform format (
icoon Windows,icnson Mac), PyInstaller tries to use Pillow to translate the icon into the correct format (if Pillow is installed). - use
"NONE"to not apply any icon at all, which makes the OS show some default. (default: apply PyInstaller's icon) - this option can be used multiple times. π
--disable-windowed-tracebackβ disables the traceback dump of unhandled exception in windowed (noconsole) mode (Windows and macOS only), and instead displays a message that this feature is disabled.
πͺ Windows specific options: πͺ
--version-file FILEβ adds a version resource from FILE to the exe.--manifest <FILE or XML>β adds manifest FILE or XML to the exe.-m <FILE or XML>β Deprecated shorthand for--manifest. it's giving legacy, use the long one.-rRESOURCE,--resourceRESOURCE β bestie, this one adds or updates a resource inside a Windows executable. RESOURCE is one to four items, and they go like this:FILE[,TYPE[,NAME[,LANGUAGE]]]. TheFILEcan be a data file, or it can be an exe/dll. If it's a data file, you gotta give at leastTYPEandNAMEβ no skipping.LANGUAGEdefaults to0, or you can throw a wildcard*in there to update, like, all the resources of that givenTYPEandNAME. Now ifFILEis an exe/dll, then every resource fromFILEgets added/updated into the final executable as long asTYPE,NAMEandLANGUAGEare omitted or set to wildcard*. And yeah, you can use this option more than once. Go off. π--uac-adminβ flip this on and you get a Manifest that will request elevation the moment the app starts. UAC popup, here we come. π₯--uac-uiaccessβ this one lets an elevated application play nice with Remote Desktop. Teamwork, honestly.
π Mac OS specific options π
--argv-emulationβ turns on argv emulation for macOS app bundles. When it's enabled, that very first open-document/URL event gets processed by the bootloader, and the file paths or URLs that come with it get appended tosys.argv. Cute, right? π¦--osx-bundle-identifierBUNDLE_IDENTIFIER β the macOS.appbundle identifier, which gets used as the default unique program name for code signing purposes. The usual form is a hierarchical name in reverse DNS notation. Example, because examples slay:
com.mycompany.department.appname
Default here is the first script's basename, bestie. Don't forget. β¨
--target-architectureARCH,--target-archARCH β the target architecture, macOS only, and the valid values are exactlyx86_64,arm64, anduniversal2. This is what lets you switch between theuniversal2version and the single-arch version of your frozen application β provided your Python installation actually supports the target architecture, okay? And if you don't specify a target architecture at all, then the current running architecture is what gets targeted. Periodt. π--codesign-identityIDENTITY β the code signing identity (macOS only). Use the identity you pass in to sign the collected binaries and the generated executable. If you don't provide a signing identity? Then adhoc signing is what happens instead. It's giving fallback. π--osx-entitlements-fileFILENAME β the entitlements file to use when code-signing the collected binaries (macOS only). That's it, that's the whole vibe. πΈ
π Rarely used special options π
These are the deep-lore options. You probably don't need them. But if you do, you really do. π
--runtime-tmpdirPATH β where to extract libraries and support files when you're inonefilemode. If you pass this, the bootloader will ignore any temp-folder location that the run-time OS defined, and the_MEIxxxxxx-folder gets created right here instead. Please only use this option if you know what you are doing β for real, no cap.
Heads up bestie: on POSIX systems, PyInstaller's bootloader does NOT perform shell-style environment variable expansion on the given path string. So using environment variables (like~or$HOME) in the path will NOT work. It's giving literally no expansion. π
--bootloader-ignore-signalsβ tells the bootloader to ignore signals instead of forwarding them to the child process. Super useful in situations where, say, a supervisor process signals both the bootloader and the child (like via a process group) β this way you avoid signalling the child twice. Main character anti-double-signal energy. π
And that's a wrap on the options, bestie β you made it to the end and honestly? Iconic behavior. π«Ά
This whole page is from PyInstaller version 6.10.0, dated October 2024, and it lives in the manual as PyInstaller(1). Now go freeze something and slay. πβ¨
π¦ where this page comes from
- debian trixie: pyinstaller 6.13.0+ds-2 Β· GPL-2+~with-bootloader-exception
- ubuntu stonking: pyinstaller 6.22.2+ds-2ubuntu3 Β· GPL-2+~with-bootloader-exception
- Copyright 2024 Soren Stoutner <soren@debian.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms