A person pulling a lever on a large machine that feeds a script through a hopper into a C compiler, which outputs packaged boxes stamped with the Python logo.

Nuitka: Compile Python Into a Standalone Executable

Nuitka is a Python compiler that turns your code into a native executable. Its distribution modes let you package an application to run on a compatible machine without a separate Python installation. A more common way to do this is to use a bundler like PyInstaller, which ships your application together with the Python runtime and its dependencies. Nuitka instead compiles your Python code to C before building the executable.

That distinction matters when you’re deciding how to distribute a Python application. Depending on your workload and build mode, Nuitka can offer performance benefits, but they come with trade-offs, including longer build times and additional compiler requirements.

By the end of this tutorial, you’ll understand that:

  • Nuitka compiles your Python code to C, while PyInstaller bundles your code with the Python interpreter.
  • --mode=standalone produces a folder, --mode=onefile produces a single file that starts more slowly, and --mode=app picks a platform-appropriate format.
  • Nuitka’s speedup depends on the workload, and CPU-bound code dominated by Python-level loops benefits the most.
  • Nuitka is worth considering when your own benchmarks show a speedup that justifies the C compiler dependency and longer build times.

In this tutorial, you’ll compile a small command-line tool and see where compiling pays off. To follow along, you should be comfortable running Python scripts from the terminal and using a virtual environment. You don’t need any experience with C. Nuitka drives the compiler for you.

Take the Quiz: Test your knowledge with our interactive “Nuitka: Compile Python Into a Standalone Executable” quiz. You’ll receive a score upon completion to help you track your learning progress:


Interactive Quiz

Nuitka: Compile Python Into a Standalone Executable

Test your understanding of compiling Python with Nuitka, from standalone and onefile builds to speedups and when PyInstaller fits better.

Getting Started With Nuitka

Before you compile your first Python application, you’ll need Nuitka and a supported C compiler. This tutorial uses Python 3.13.15 for the builds shown below. The compiler setup is discussed later in this section.

You can use uv to create an isolated environment and install Nuitka. If you don’t have uv installed, use the venv and pip alternative described after these steps. Create the environment with uv:

Language: Shell
$ uv venv --python 3.13.15

Activate the environment. On macOS and Linux, run the following command:

Language: Shell
$ source .venv/bin/activate

In Windows PowerShell, run the following command:

Language: Windows PowerShell
PS> .\.venv\Scripts\Activate.ps1

In the commands below, (.venv) indicates an activated Python virtual environment, whether you created it with venv, uv venv, or another tool.

Then install the version of Nuitka used for this tutorial:

Language: Shell
(.venv) $ uv pip install nuitka==4.2.1

Alternatively, create the environment with python -m venv .venv, activate it using the appropriate command above, and install Nuitka with python -m pip install nuitka==4.2.1. The rest of the tutorial uses python -m nuitka, so the build commands work the same way once the environment is activated.

Nuitka uses a C toolchain during compilation, and the compiler setup depends on your operating system. Check the official installation documentation for the current platform-specific requirements.

For this tutorial, you’ll use a small command-line program that counts the most common words in a text file. Save the following code as wordcount.py:

Language: Python Filename: wordcount.py
from argparse import ArgumentParser
from collections import Counter
from pathlib import Path

def main():
    parser = ArgumentParser(
        description="Show the most common words in a text file."
    )
    parser.add_argument("file", type=Path)
    parser.add_argument("-n", "--top", type=int, default=5)
    args = parser.parse_args()

    words = args.file.read_text(encoding="utf-8").lower().split()

    for word, count in Counter(words).most_common(args.top):
        print(f"{word}: {count}")

if __name__ == "__main__":
    main()

This script reads a text file, counts word frequency, and prints the most common entries.

Save the following text as sample.txt in the same directory:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Article

Already a member? Sign-In

Locked learning resources

The full article is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Article

Already a member? Sign-In

About Shanzia Shabnom Mithun

Shanzia is a Machine Learning Engineer and Python enthusiast with a background in machine learning, data science, and research. She enjoys using Python to explore new technologies and build practical solutions to real-world problems.

» More about Shanzia Shabnom

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

What Do You Think?

What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.

Commenting Tips: The most useful comments are those written with the goal of learning from or helping out other students. Get tips for asking good questions and get answers to common questions in our support portal.


Looking for a real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!

Become a Member to join the conversation.

Keep Learning

Related Topics: intermediate python tools