pyinstaller
command is:pyinstaller
[options] script [script …] | specfilemyscript.py
and execute:myscript.py
and:myscript.spec
in the same folder as the script.build
in the same folder as the script if it does not exist.build
folder.dist
in the same folder as the script if it does not exist.myscript
executable folder in the dist
folder.dist
folder you find the bundled app you distribute to your users.myscript.spec
(described under Using Spec Files).After you do this, you name the spec file to PyInstaller instead of the script:pyinstallermyscript.spec
myscript.spec
file contains most of the informationprovided by the options that were specified whenpyinstaller (or pyi-makespec)was run with the script file as the argument.You typically do not need to specify any options when runningpyinstaller with the spec file.Only a few command-line optionshave an effect when building from a spec file.pyinstaller'C:DocumentsandSettingsprojectmyscript.spec'
-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, .pyzand etc. (default: ./build) | |
-y, --noconfirm | |
Replace output directory (default:SPECPATH/dist/SPECNAME) without asking forconfirmation | |
--upx-dir UPX_DIR | |
Path to UPX utility (default: search the executionpath) | |
-a, --ascii | Do not include unicode encoding support (default:included if available) |
--clean | Clean PyInstaller cache and remove temporary filesbefore building. |
--log-level LEVEL | |
Amount of detail in build-time console messages. LEVELmay be one of TRACE, DEBUG, INFO, WARN, ERROR,CRITICAL (default: INFO). |
-D, --onedir | Create a one-folder bundle containing an executable(default) |
-F, --onefile | Create a one-file bundled executable. |
--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) |
--add-data <SRC;DEST or SRC:DEST> | |
Additional non-binary files or folders to be added tothe executable. The path separator is platformspecific, os.pathsep (which is ; on Windowsand : on most unix systems) is used. This optioncan be used multiple times. | |
--add-binary <SRC;DEST or SRC:DEST> | |
Additional binary files to be added to the executable.See the --add-data option for more details. Thisoption can be used multiple times. | |
-p DIR, --paths DIR | |
A path to search for imports (like using PYTHONPATH).Multiple paths are allowed, separated by ‘:’, or usethis option multiple times | |
--hidden-import MODULENAME, --hiddenimport MODULENAME | |
Name an import not visible in the code of thescript(s). This option can be used multiple times. | |
--additional-hooks-dir HOOKSPATH | |
An additional path to search for hooks. This optioncan be used multiple times. | |
--runtime-hook RUNTIME_HOOKS | |
Path to a custom runtime hook file. A runtime hook iscode that is bundled with the executable and isexecuted before any other code or module to set upspecial features of the runtime environment. Thisoption can be used multiple times. | |
--exclude-module EXCLUDES | |
Optional module or package (the Python name, not thepath name) that will be ignored (as though it was notfound). This option can be used multiple times. | |
--key KEY | The key used to encrypt Python bytecode. |
-d <all,imports,bootloader,noarchive>, --debug <all,imports,bootloader,noarchive> | |
Provide assistance with debugging a frozenapplication. This argument may be provided multipletimes to select several of the following options.
| |
-s, --strip | Apply a symbol-table strip to the executable andshared libs (not recommended for Windows) |
--noupx | Do not use UPX even if it is available (worksdifferently between Windows and *nix) |
--upx-exclude FILE | |
Prevent a binary from being compressed when using upx.This is typically used if upx corrupts certainbinaries during compression. FILE is the filename ofthe binary without path. This option can be usedmultiple times. |
-c, --console, --nowindowed | |
Open a console window for standard i/o (default). OnWindows this option will have no effect if the firstscript is a ‘.pyw’ file. | |
-w, --windowed, --noconsole | |
Windows and Mac OS X: do not provide a console windowfor standard i/o. On Mac OS X this also triggersbuilding an OS X .app bundle. On Windows this optionwill be set if the first script is a ‘.pyw’ file. Thisoption is 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 that 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 OSX |
--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 RESOURCE, --resource RESOURCE | |
Add or update a resource to a Windows executable. TheRESOURCE is one to four items,FILE[,TYPE[,NAME[,LANGUAGE]]]. FILE can be a data fileor an exe/dll. For data files, at least TYPE and NAMEmust be specified. LANGUAGE defaults to 0 or may bespecified as wildcard * to update all resources of thegiven TYPE and NAME. For exe/dll files, all resourcesfrom FILE will be added/updated to the finalexecutable if TYPE, NAME and LANGUAGE are omitted orspecified as wildcard *.This option can be usedmultiple times. | |
--uac-admin | Using this option creates a Manifest which willrequest elevation upon application restart. |
--uac-uiaccess | Using this option allows an elevated application towork with Remote Desktop. |
--win-private-assemblies | |
Any Shared Assemblies bundled into the applicationwill be changed into Private Assemblies. This meansthe exact versions of these assemblies will always beused, and any newer versions installed on usermachines at the system level will be ignored. | |
--win-no-prefer-redirects | |
While searching for Shared or Private Assemblies tobundle into the application, PyInstaller will prefernot to follow policies that redirect to newerversions, and will try to bundle the exact versions ofthe assembly. |
--osx-bundle-identifier BUNDLE_IDENTIFIER | |
Mac OS X .app bundle identifier is used as the defaultunique program name for code signing purposes. Theusual form is a hierarchical name in reverse DNSnotation. For example:com.mycompany.department.appname (default: firstscript’s basename) |
--runtime-tmpdir PATH | |
Where to extract libraries and support files inonefile-mode. If this option is given, thebootloader will ignore any temp-folder locationdefined by the run-time OS. The _MEIxxxxxx -folderwill be created here. Please use this option only ifyou know what you are doing. | |
--bootloader-ignore-signals | |
Tell the bootloader to ignore signals rather thanforwarding them to the child process. Useful insituations where e.g. a supervisor process signalsboth the bootloader and child (e.g. via a processgroup) to avoid signalling the child twice. |
pyinstaller
commandcan become very long.You will run the same command again and again as you developyour script.You can put the command in a shell script or batch file,using line continuations to make it readable.For example, in GNU/Linux:run
function of the __main__
module and pass all command line arguments in asa list, e.g.-O
, __debug__
is setto False
and assert
statements are removed from the bytecode.The -OO
flag additionally removes docstrings.-O
or -OO
)by executing it as a Python module, rather than using the pyinstaller
command:PYTHONOPTIMIZE
environment variableto a non-zero value:pyinstaller
command. For example:--upx-dir
option.If UPX exists, PyInstaller applies it to the final executable,unless the --noupx
option was given.UPX has been used with PyInstaller output often, usually with no problems.--key=
key-string argument onthe command line.--runtime-tmpdir
option. If this option isgiven, the bootloader will ignore any temp-folder location defined by therun-time OS. Please use this option only if you know what you are doing.pyi-grab_version
command.It is invoked with the full path name of any Windows executablethat has a Version resource:pyi-grab_version
you can find an executable that displays the kind ofinformation you want, copy its resource data, and modify it to suit your package.--version-file=
option to pyinstaller
or pyi-makespec
.The text data is converted to a Version resource andinstalled in the bundled app.FileVersion
and ProductVersion
.In the version text file these are given as four-element tuples,for example:(2,0,4,0)
resolves to0002000000040000
in hex.pyi-set_version
command:pyi-set_version
version_text_fileexecutable_filepyi-set_version
utility reads a version text file as writtenby pyi-grab_version
, converts it to a Version resource,and installs that resource in the executable_file specified.pyi-grab_version
.You find it is Python code that creates a VSVersionInfo
object.The class definition for VSVersionInfo
is found inutils/win32/versioninfo.py
in the PyInstaller distribution folder.You can write a program that imports versioninfo
.In that program you can eval
the contents of a version info text file to produce aVSVersionInfo
object.You can use the .toRaw()
method of that object toproduce a Version resource in binary form.Or you can apply the unicode()
function to the objectto reproduce the version text file.dist
.If you specify --onedir
, the output is a folder named myscript
containing supporting files and an executable named myscript
.If you specify --onefile
, the output is a single UNIX executablenamed myscript
.Either executable can be started from a Terminal command line.Standard input and output work as normal through that Terminal window.--windowed
with either option, the dist
folderalso contains an OS X application named myscript.app
.Contents
which contains:Frameworks
which is empty.Resources
that contains an icon file.Info.plist
that describes the app.MacOS
that contains the the executable andsupporting files, just as in the --onedir
folder.icon=
argument to specify a custom icon for the application.It will be copied into the Resources
folder.(If you do not specify an icon file, PyInstaller supplies afile icon-windowed.icns
with the PyInstaller logo.)osx-bundle-identifier=
argument to add a bundle identifier.This becomes the CFBundleIdentifier
used in code-signing(see the PyInstaller code signing recipeand for more detail, the Apple code signing overview technical note).Info.plist
by editing the spec file;see Spec File Options for a Mac OS X Bundle Quickbooks app for mac desktop is now working. below.libc
(the C standard library, usually glibc
, the Gnu version) with the app.Instead, the app expects to link dynamically to the libc
from thelocal OS where it runs.The interface between any app and libc
is forward compatible tonewer releases, but it is not backward compatible to older releases.libc
found on newer versions.glibc
are distributed in 64-bitand 32-bit versions, and these are not compatible.As a result you cannot bundle your app on a 32-bit system and run iton a 64-bit installation, nor vice-versa.You must make a unique version of the app for each word-length supported.file
command to the Python executable:arch
command:/usr/bin/python
may circumvent the arch
specification and run 64-bit regardless.(That is not the case if you apply arch
to a specific versionsuch as /usr/bin/python2.7
.)To make sure of running 32-bit in all cases, set the following environment variable:argv
string before starting your code.Thus your code can query sys.argv
to get the namesof documents that should be opened at startup.OBJECT_MODE
.To determine the size the following command can be used:True
(as above) Python was build as a 32-bitexecutable.