Python TutorialGetting Started with PythonPython Basic SyntaxPython DatatypesPython IndentationPython Collection TypesPython Basic Input and OutputPython Built in Modules and FunctionsPython FunctionsChemPy - python packageCreating Python packagesFunctional Programming in PythonIncompatibilities moving from Python 2 to Python 3IoT Programming with Python and Raspberry PIKivy - Cross-platform Python Framework for NUI DevelopmentMutable vs Immutable (and Hashable) in PythonPyInstaller - Distributing Python CodePython *args and **kwargsPython 2to3 toolPython Abstract Base Classes (abc)Python Abstract syntax treePython Alternatives to switch statement from other languagesPython and ExcelPython Anti-PatternsPython ArcPyPython ArraysPython Asyncio ModulePython Attribute AccessPython AudioPython Binary DataPython Bitwise OperatorsPython Boolean OperatorsPython Checking Path Existence and PermissionsPython ClassesPython CLI subcommands with precise help outputPython Code blocks, execution frames, and namespacesPython Collections modulePython Comments and DocumentationPython Common PitfallsPython Commonwealth ExceptionsPython ComparisonsPython Complex mathPython concurrencyPython ConditionalsPython configparserPython Context Managers (with Statement)Python Copying dataPython CountingPython ctypesPython Data SerializationPython Data TypesPython Database AccessPython Date and TimePython Date FormattingPython DebuggingPython DecoratorsPython Defining functions with list argumentsPython DeploymentPython Deque ModulePython DescriptorPython Design PatternsPython DictionaryPython Difference between Module and PackagePython DistributionPython DjangoPython Dynamic code execution with `exec` and `eval`Python EnumPython ExceptionsPython ExponentiationPython Files & Folders I/OPython FilterPython FlaskPython Functools ModulePython Garbage CollectionPython GeneratorsPython getting start with GZipPython graph-toolPython groupby()Python hashlibPython HeapqPython Hidden FeaturesPython HTML ParsingPython HTTP ServerPython IdiomsPython ijsonPython Immutable datatypes(int, float, str, tuple and frozensets)Python Importing modulesPython Indexing and SlicingPython Input, Subset and Output External Data Files using PandasPython Introduction to RabbitMQ using AMQPStorm

PyInstaller - Distributing Python Code

From WikiOD

Syntax[edit | edit source]

  • pyinstaller [options] script [script ...] | specfile

Remarks[edit | edit source]

PyInstaller is a module used to bundle python apps in a single package along with all the dependencies. The user can then run the package app without a python interpreter or any modules. It correctly bundles many major packages like numpy, Django, OpenCv and others.

Some important points to remember:

  • Pyinstaller supports Python 2.7 and Python 3.3+
  • Pyinstaller has been tested against Windows, Linux and Mac OS X.
  • It is NOT cross compiler. (A Windows app cannot be packaged in Linux. You've to run PyInstaller in Windows to bundle an app for Windows)

Homepage Official Docs

Installation and Setup[edit | edit source]

Pyinstaller is a normal python package. It can be installed using pip:

pip install pyinstaller

Installation in Windows

For Windows, pywin32 or pypiwin32 is a prerequisite. The latter is installed automatically when pyinstaller is installed using pip.

Installation in Mac OS X

PyInstaller works with the default Python 2.7 provided with current Mac OS X. If later versions of Python are to be used or if any major packages such as PyQT, Numpy, Matplotlib and the like are to be used, it is recommended to install them using either MacPorts or Homebrew.

Installing from the archive

If pip is not available, download the compressed archive from PyPI.

To test the development version, download the compressed archive from the develop branch of PyInstaller Downloads page.

Expand the archive and find the script. Execute python install with administrator privilege to install or upgrade PyInstaller.

Verifying the installation

The command pyinstaller should exist on the system path for all platforms after a successful installation.

Verify it by typing pyinstaller --version in the command line. This will print the current version of pyinstaller.

Using Pyinstaller[edit | edit source]

In the simplest use-case, just navigate to the directory your file is in, and type:


Pyinstaller analyzes the file and creates:

  • A myfile.spec file in the same directory as
  • A build folder in the same directory as
  • A dist folder in the same directory as
  • Log files in the build folder

The bundled app can be found in the dist folder


There are several options that can be used with pyinstaller. A full list of the options can be found here.

Once bundled your app can be run by opening 'dist\myfile\myfile.exe'.

Bundling to One Folder[edit | edit source]

When PyInstaller is used without any options to bundle , the default output is a single folder (named myscript) containing an executable named myscript (myscript.exe in windows) along with all the necessary dependencies.

The app can be distributed by compressing the folder into a zip file.

One Folder mode can be explictly set using the option -D or --onedir

pyinstaller -D

Advantages:[edit | edit source]

One of the major advantages of bundling to a single folder is that it is easier to debug problems. If any modules fail to import, it can be verified by inspecting the folder.

Another advantage is felt during updates. If there are a few changes in the code but the dependencies used are exactly the same, distributors can just ship the executable file (which is typically smaller than the entire folder).

Disadvantages[edit | edit source]

The only disadvantage of this method is that the users have to search for the executable among a large number of files.

Also users can delete/modify other files which might lead to the app not being able to work correctly.

Bundling to a Single File[edit | edit source]

pyinstaller -F

The options to generate a single file are -F or --onefile. This bundles the program into a single myscript.exe file.

Single file executable are slower than the one-folder bundle. They are also harder to debug.