ScriptsApr 27, 2026·3 min read

Nuitka — Compile Python to Standalone Executables

Turn any Python program into optimized C code and ship it as a single binary with no interpreter required.

Introduction

Nuitka is a Python compiler that translates Python source into C code and links it against libpython to produce native executables. It supports the full Python language including dynamic features, while delivering measurable speedups and true standalone distribution.

What Nuitka Does

  • Compiles Python modules and packages into C code via a whole-program optimizer
  • Produces standalone executables or single-file binaries with all dependencies bundled
  • Supports CPython 3.4 through 3.12 and the complete standard library
  • Applies constant folding, dead code elimination, and type inference optimizations
  • Handles C extensions, data files, and Qt/Tk/PyGame resources automatically

Architecture Overview

Nuitka parses Python source into its own AST, performs optimization passes (constant propagation, escape analysis, type specialization), then emits C source files. These are compiled with gcc or MSVC and linked against the CPython runtime. For standalone mode, Nuitka traces all imports, bundles shared libraries, and optionally compresses everything into a single executable using AppImage or NSIS.

Self-Hosting & Configuration

  • Install via pip: pip install nuitka
  • Requires a C compiler (gcc on Linux, MSVC or MinGW on Windows, clang on macOS)
  • Use --standalone to bundle all dependencies into a dist folder
  • Use --onefile to produce a single executable archive
  • Configure via nuitka-project: comment directives inside your source files

Key Features

  • Full Python compatibility — handles metaclasses, decorators, generators, and async
  • Whole-program optimization with measurable 2-4x speedups on CPU-bound code
  • Standalone and onefile output modes for easy distribution
  • Plugin system for NumPy, Qt, Tk, PyGame, and other frameworks
  • Commercial-friendly Apache 2.0 license

Comparison with Similar Tools

  • PyInstaller — bundles the interpreter and bytecode but does not compile to native code; no speedup
  • cx_Freeze — similar to PyInstaller with cross-platform freeze but no compilation
  • Cython — compiles annotated Python to C but requires type annotations for best results
  • mypyc — compiles type-annotated Python via mypy but limited to a subset of the language
  • PyOxidizer — embeds Python in a Rust binary; focuses on packaging, not optimization

FAQ

Q: Does Nuitka support the full Python language? A: Yes. It compiles all CPython-compatible code including dynamic imports, eval, and metaclasses.

Q: How much faster is compiled code? A: CPU-bound code often sees 2-4x improvement. IO-bound code benefits less since the bottleneck is external.

Q: Can I compile packages with C extensions? A: Yes. Nuitka bundles C extensions as-is alongside the compiled Python code.

Q: Is the output binary portable? A: Standalone binaries include all dependencies and run on the same OS and architecture without Python installed.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets