Why Nuitka Beats PyInstaller: Tiny 7 MB EXEs vs 3 GB Bloat

This article compares PyInstaller and Nuitka for converting Python projects into executables, highlighting Nuitka's dramatically smaller output size, faster build and startup times, and provides step‑by‑step installation and command‑line usage instructions.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Why Nuitka Beats PyInstaller: Tiny 7 MB EXEs vs 3 GB Bloat

1. Experience with PyInstaller and Nuitka

1.1 Requirements

This project needed to convert Python code to an exe; two tools were found: PyInstaller and Nuitka.

Both tools meet the project needs:

Hide source code . PyInstaller encrypts source with a key; Nuitka compiles Python to C++ (binary .pyd) preventing decompilation.

Easy portability . Users can run without installing Python or third‑party packages.

1.2 Impressions

The main impressions after using the two tools are:

PyInstaller experience is poor: a deep‑learning project produces an exe of nearly 3 GB, packaging the whole runtime; packaging and startup are extremely slow.

Nuitka is great: the same project yields a 7 MB exe, packaging completes in under a minute and starts instantly.

2. Installing and Using Nuitka

2.1 Installation

Install via pip: pip install Nuitka Download a C++ compiler such as VS2019 (MSVC) or MinGW‑64.

2.2 Usage

For projects with many third‑party dependencies (torch, tensorflow, cv2, numpy, pandas, geopy, etc.), it is best to compile only your own code to C++ and leave the large external packages untouched.

Example directory structure:

├─utils/   # source folder 1
├─src/     # source folder 2
├─logo.ico # demo icon
└─demo.py  # main script

Generate an exe with debugging:

nuitka --standalone --show-memory --show-progress --nofollow-imports --plugin-enable=qt-plugins --follow-import-to=utils,src --output-dir=out --windows-icon-from-ico=./logo.ico demo.py

Explanation of the options:

--standalone: makes the exe portable without requiring a Python installation.

--show-memory, --show-progress: display progress and memory usage.

--nofollow-imports: do not compile imported modules such as keras, numpy.

--plugin-enable=qt-plugins: enables the Qt plugin needed for PyQt5.

--follow-import-to=utils,src: compile only the specified source folders to C++.

--output-dir=out: place the build output in the out directory.

--windows-icon-from-ico=./logo.ico: set the exe icon.

--windows-disable-console: (optional) hide the console window.

After about one minute of compilation, the output directory contains:

├─utils/
├─src/
├─out/
   ├─demo.build/
   └─demo.dist/
       └─demo.exe
├─logo.ico
└─demo.py

When running the exe, missing third‑party modules (e.g., torch, cv2, tensorflow) will cause import errors. Copy the required package folders from site‑packages into demo.dist to resolve them. After that, the exe runs correctly.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceCpyinstallerexecutable packagingNuitka
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.