Nuitka and PyQtgraph - Bundle a Python Application into a Standalone Binary
05/01/2023, MonPyQtgraph Standalone Application
Nuitka is a Python compiler that supports the conversion of a Python application to compiled code. It enables you to create a single file executable for convenient distribution.
Prerequisites
You will need a C compiler and a Python version specified in the Nuitka README.md.
Installing Nuitka
python3 -m pip install nuitka
Compilation Options
Simple bundle command
Once nuitka is installed, you will navigate to your Python project folder and run this minimal command to get an application compiled. By default, this basic command will not output a single executable file.
nuitka main.py
Dynamic imports
Since PyQtGraph uses dynamic imports, you will need to tell nuitka to include these dependencies for the
nuitka --follow-imports --include-plugin-directory=mods main.py
PyQtgraph Bundling Options
PyQtgraph uses dynamic imports and requires the '--follow-imports' graph.
python3 -m nuitka main.py --follow-imports --onefile --enable-plugin=pyqt6
Here is the command and options if you are using poetry with nuitka.
poetry run python -m nuitka main.py --follow-imports --onefile --enable-plugin=pyqt6
You might have to install some other python modules to speed up performance based on the warnings that nuitka outputs when using poetry.
Result
This will create a standalone binary, main.bin, that is about 52 megabytes.