Nuitka is the optimizing Python compiler written in Python that creates executables that run without a separate installer. Data files can both be included or put alongside.
You can read more on the official website.
The install is easy with pip tool, then you can use this command.
python -m nuitka --help
Usage: python.exe -m nuitka [--mode=compilation_mode] [--run] [options] main_module.py
Note: For general plugin help (they often have their own
command line options too), consider the output of
'--help-plugins'.
Options:
--help show this help message and exit
--version Show version information and important details for bug
reports, then exit. Defaults to off.This python package need to have the Visual Studio Build Tools 2022 and need to use:
- Desktop development with C++
- MSVC v143 build tools
- Windows 10/11 SDK
- C++ CMake tools
- C++ ATL/MFC (optional but useful)
Let's install it.
I used this simple example:
import sys
from PyQt6.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout
def main():
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle("PyQt6 + Nuitka Demo")
layout = QVBoxLayout()
label = QLabel("Hello! This is a PyQt6 application compiled with Nuitka.")
layout.addWidget(label)
window.setLayout(layout)
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()Use this command to see all plugins:
nuitka --plugin-list
The following plugins are available in Nuitka
--------------------------------------------------------------------------------
delvewheel Required by 'delvewheel' using packages. (core)
implicit-imports Provide implicit imports of package as per package configuration files. (core) [auto-enabled]
data-files Include data files specified by package configuration files. (core, feature)
dll-files Include DLLs as per package configuration files. (core, feature)
anti-bloat Patch stupid imports out of widely used library modules source codes. (core, feature, package-support) [auto-enabled]
options-nanny Inform user about potential problems as per package configuration files. (core, package-support) [auto-enabled]
pylint-warnings Support PyLint / PyDev linting source markers. (feature)
upx Compress created binaries with UPX automatically. (integration)
dill-compat Required by 'dill' and 'cloudpickle' packages. (package-support) [has detector]
eventlet Required by 'eventlet' package. (package-support) [auto-enabled]
gevent Required by 'gevent' package. (package-support)
gi Required by 'gi' package. (package-support) [auto-enabled]
glfw Required by 'glfw' and 'PyOpenGL' packages. (package-support)
kivy Required by 'kivy' package. (package-support)
matplotlib Required by 'matplotlib' package. (package-support)
multiprocessing Required by 'multiprocessing' package. (package-support) [auto-enabled]
no-qt Disable inclusion of all Qt bindings. (package-support)
pbr-compat Required by 'pbr' package. (package-support)
pkg-resources Required by 'pkg_resources' package. (package-support) [auto-enabled]
playwright Required by 'playwright' package. (package-support)
pmw-freezer Required by 'Pmw' package. (package-support) [has detector]
pywebview Required by 'webview' package. (package-support)
spacy Required by 'spacy' package. (package-support)
tk-inter Required by 'tkinter' package. (package-support) [has detector]
transformers Required by 'transformers' package. (package-support) [auto-enabled]
enum-compat Required by 'enum' package on Python2. (package-support, python2)
pyqt5 Required by 'PyQt5' package. (package-support, qt-binding) [has detector]
pyqt6 Required by 'PyQt6' package. (package-support, qt-binding) [has detector]
pyside2 Required by 'PySide2' package. (package-support, qt-binding) [has detector]
pyside6 Required by 'PySide6' package. (package-support, qt-binding) [has detector]... and standalone build process:
nuitka --standalone --enable-plugin=pyqt6 test_app.py
Nuitka-Options: Used command line options:
Nuitka-Options: --standalone --enable-plugin=pyqt6 test_app.py
Nuitka-Plugins:pyqt6: Support for PyQt6 is not perfect, e.g. Qt threading does not work, so prefer
Nuitka-Plugins:pyqt6: PySide6 if you can.
Nuitka: Starting Python compilation with:
Nuitka: Version '4.0.8' on Python 3.10 (flavor 'CPython Official')
Nuitka: commercial grade 'not installed'.
Nuitka-Plugins:pyqt6: Including Qt plugins 'iconengines,imageformats,platforms,styles,tls' below
Nuitka-Plugins:pyqt6: 'PyQt6\Qt6\plugins'.
Nuitka: Completed Python level compilation and optimization.
Nuitka: Generating source code for C backend compiler.
Nuitka: Running data composer tool for optimal constant value handling.
Nuitka: Running C compilation via Scons.
Nuitka will use gcc from MinGW64 of winlibs to compile on Windows.
Is it OK to download and put it in local user cache.
Fully automatic, cached. Proceed and download? [Yes]/No :
Nuitka: Downloading
Nuitka: 'https://github.com/brechtsanders/winlibs_mingw/releases/download/14.2.0posix-19.1.1-12.0.0-msvcrt-r2/winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-19.1.1-mingw-w64msvcrt-12.0.0-r2.zip'.
Nuitka: Extracting to
Nuitka: 'C:\Users\CATALI~1\AppData\Local\Nuitka\Nuitka\Cache\DOWNLO~1\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\mingw64\bin\gcc.exe'
Nuitka-Scons: Backend C compiler: gcc (gcc 14.2.0).
Nuitka-Scons: Backend C linking with 9 files (no progress information available for this stage).
Nuitka-Scons: Compiled 9 C files using ccache.
Nuitka-Scons: Cached C files (using ccache) with result 'cache miss': 9
Nuitka: Keeping build directory 'test_app.build'.
Nuitka: Successfully created 'C:\lucru\PyQt6\test_nuitka\test_app.dist\test_app.exe'.
