Bundle Simple Python Application using PyInstaller
How to build a self-contained python package (executable) using PyInstaller library

Enjoy working in embedded systems and tools development. I blog about automation and application development using Python.
I am a senior software developer and has more than 6 years of experience in semiconductor industry. I work on tools development those are used in every stages of device life cycle. Also, have experience in device driver development.
Introduction
PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules. PyInstaller is tested against Windows, MacOS X, and Linux. However, it is not a cross-compiler; to make a Windows app you run PyInstaller on Windows, and to make a Linux app you run it on Linux, etc.
Prerequisite
- Operating system: Windows 10 or above (It can be used in other OS as well)
- Python version: 3.7.6 or above (It works for python 2.7 versions as well)
Please download and install python 3 in your system. You can follow this video to install python 3. Then install PyInstaller from PyPI using command pip install pyinstaller.
Building executable
- Lets say we have only one file main.py
- Run command
pyinstaller --onefile main.py - This will create two folders dist and build
- You can find main.exe inside dist folder
- This command will also create main.spec file in current directory (We will talk about this in next article)
- Run command
- Useful flags
- -D,--onedir: one-folder bundle containing an executable
- -F, --onefile: one-file bundled executable
- -n NAME, --name NAME: Name for bundled app
- --distpath DIR: Location of bundled app
- Please follow this documentation for all the flags available for pyinstaller.



