Sitemap

PyInstaller

2 min readJul 24, 2024

Needs:

You’ve been given a job to automate some daily tasks. After you finish coding and testing your program, the real challenge is to deliver it to the user. The program should be simple for the user to run without knowing much about Python. The main problem is including all the third-party libraries your script needs so the user doesn’t have to worry about any dependencies. PyInstaller helps solve this problem.

About:

PyInstaller is a tool that converts your Python program into stand-alone executables. It bundles the Python interpreter and the required modules into a single package, so the user does not need to install Python or any Python modules. It will support CLI and Windows applications It comes under GPL licenses. Pyinstller output is specific to the active OS version and Python version.

System requirements:

There is no specific requirement for Mac or Windows.

For Mac, It can run on macOS 10.15 (Catalina) or newer

For Windows, It can run on Windows 8 or newer

For Linux, the commands ldd and objdump are required. Additionally, packages like glibc or libc-bin are needed.

Installation:

pip install pyinstaller

Upgrade:

pip install --upgrade pyinstaller

Version:

pyinstaller --version

Base Case: Create Executables

Get Shankar Duraisamy’s stories in your inbox

Join Medium for free to get updates from this writer.

To create executables from the Python script, go to the script's home directory and run the below command. It will generate an executable file inside the “dist” directory. The default mode will create a directory with executables and its dependencies

pyinstaller script_name.py

From Spec File

To create an executable from an existing.spec file

pyinstaller driver.spec

One-File:

To bundle all the dependencies into a single executable.

pyinstaller --onefile --name=name_of_executables script_name.py --paths=path_to_libray_to_bundle --add-binary path_to_dll

Windows App:

pyinstaller script_name.py --onefile --windowed

To Handle hidden import

In Python, one module might depend on another module. PyInstaller can handle this by bundling all the modules, including hidden ones, into the executable.

pyinstaller --hidden-import=module_name script_name.py