Use Cases

Use Case 1 — Program compilation with all modules embedded

If you want to compile a whole program recursively, and not only the single file that is the main program, do it like this:

python -m nuitka --follow-imports


There are more fine-grained controls than --follow-imports available. Consider the output of nuitka --help. Including fewer modules into the compilation, but instead using normal Python for it, will make it faster to compile.

In case you have a source directory with dynamically loaded files, i.e. one which cannot be found by recursing after normal import statements via the PYTHONPATH (which would be the recommended way), you can always require that a given directory shall also be included in the executable:

python -m nuitka --follow-imports --include-plugin-directory=plugin_dir


If you don’t do any dynamic imports, simply setting your PYTHONPATH at compilation time is what you should do.

Use --include-plugin-directory only if you make __import__() calls that Nuitka cannot predict, and that come from a directory, for everything from your Python installation, use --include-module or --include-package.


The resulting filename will be program.exe on Windows, program.bin on other platforms, but --output-filename allows changing that.


The resulting binary still depends on CPython and used C extension modules being installed.

If you want to be able to copy it to another machine, use --standalone and copy the created program.dist directory and execute the program.exe (Windows) or program (other platforms) put inside.

Use Case 2 — Extension Module compilation

If you want to compile a single extension module, all you have to do is this:

python -m nuitka --module

The resulting file can then be used instead of


The filename of the produced extension module must not be changed as Python insists on a module name derived function as an entry point, in this case PyInit_some_module and renaming the file will not change that. Match the filename of the source code to what the binary name should be.


If both the extension module and the source code of it are in the same directory, the extension module is loaded. Changes to the source code only have effect once you recompile.


The option --follow-import-to works as well, but the included modules will only become importable after you imported the some_module name. If these kinds of imports are invisible to Nuitka, e.g. dynamically created, you can use --include-module or --include-package in that case, but for static imports it should not be needed.


An extension module can never include other extension modules. You will have to create a wheel for this to be doable.


The resulting extension module can only be loaded into a CPython of the same version and doesn’t include other extension modules.

Use Case 3 — Package compilation

If you need to compile a whole package and embed all modules, that is also feasible, use Nuitka like this:

python -m nuitka --module some_package --include-package=some_package


The inclusion of the package contents needs to be provided manually; otherwise, the package is mostly empty. You can be more specific if you like, and only include part of it, or exclude part of it, e.g. with --nofollow-import-to='*.tests' you would not include the unused test part of your code.


Data files located inside the package will not be embedded by this process, you need to copy them yourself with this approach. Alternatively, you can use the file embedding of Nuitka commercial.

Use Case 4 — Program Distribution

For distribution to other systems, there is the standalone mode, which produces a folder for which you can specify --standalone.

python -m nuitka --standalone

Following all imports is default in this mode. You can selectively exclude modules by specifically saying --nofollow-import-to, but then an ImportError will be raised when import of it is attempted at program run time. This may cause different behavior, but it may also improve your compile time if done wisely.

For data files to be included, use the option --include-data-files=<source>=<target> where the source is a file system path, but the target has to be specified relative. For the standalone mode, you can also copy them manually, but this can do extra checks, and for the onefile mode, there is no manual copying possible.

To copy some or all file in a directory, use the option --include-data-files=/etc/*.txt=etc/ where you get to specify shell patterns for the files, and a subdirectory where to put them, indicated by the trailing slash.


Nuitka does not consider data files code, do not include DLLs, or Python files as data files, and expect them to work, they will not, unless you really know what you are doing. Refer to Code is not Data Files for more details.

Also some folders are ignored, these are site-packages, dist-packages and vendor-packages which would otherwise include a full virtualenv, which is never a good thing to happen. And the __pycache__ folder is also always ignored. On non-MacOS the file .DS_Store is ignored too, and py.typed folders have only meaning to IDEs, and are ignored like .pyi files .

To copy a whole folder with all non-code files, you can use --include-data-dir=/path/to/images=images which will place those in the destination, and if you want to use the --noinclude-data-files option to remove them. Code files are as detailed above DLLs, executables, Python files, etc. and will be ignored. For those you can use the --include-data-files=/binaries/*.exe=binary/ form to force them, but that is not recommended and known to cause issues at run-time.

For package data, there is a better way, namely using --include-package-data, which detects all non-code data files of packages automatically and copies them over. It even accepts patterns in a shell style. It spares you the need to find the package directory yourself and should be preferred whenever available. Functionally it’s very similar to --include-data-dir but it has the benefit to locate the correct folder for you.

With data files, you are largely on your own. Nuitka keeps track of ones that are needed by popular packages, but it might be incomplete. Raise issues if you encounter something in these. Even better, raise PRs with enhancements to the Nuitka Package Configuration. With want 3rd party software to just work out of the box.

When that is working, you can use the onefile mode if you so desire.

python -m nuitka --onefile

This will create a single binary, that extracts itself on the target, before running the program. But notice, that accessing files relative to your program is impacted, make sure to read the section Onefile: Finding files as well.

# Create a binary that unpacks into a temporary folder
python -m nuitka --onefile


There are more platform-specific options, e.g. related to icons, splash screen, and version information, consider the --help output for the details of these and check the section Tweaks.

For the unpacking, by default a unique user temporary path one is used, and then deleted, however this default --onefile-tempdir-spec="{TEMP}/onefile_{PID}_{TIME}" can be overridden with a path specification that is using then using a cached path, avoiding repeated unpacking, e.g. with --onefile-tempdir-spec="{CACHE_DIR}/{COMPANY}/{PRODUCT}/{VERSION}" which uses version information, and user-specific cache directory.


Using cached paths will be relevant, e.g. when Windows Firewall comes into play because otherwise, the binary will be a different one to it each time it is run.

Currently, these expanded tokens are available:


What this Expands to



User temporary file directory



Process ID



Time in seconds since the epoch.



Full program run-time filename of executable.



No-suffix of run-time filename of executable.



Cache directory for the user.



Value given as --company-name



Value given as --product-name



Combination of --file-version & --product-version


Home directory for the user.



When provided for file outputs, None is used

see notice below


When provided for file outputs, os.devnull is used

see notice below


It is your responsibility to make the path provided unique, on Windows a running program will be locked, and while using a fixed folder name is possible, it can cause locking issues in that case, where the program gets restarted.

Usually, you need to use {TIME} or at least {PID} to make a path unique, and this is mainly intended for use cases, where e.g. you want things to reside in a place you choose or abide your naming conventions.


For disabling output and stderr with --force-stdout-spec and --force-stderr-spec the values {NONE} and {NULL} achieve it, but with different effect. With {NONE}, the corresponding handle becomes None. As a result, e.g. sys.stdout will be None, which is different from {NULL} where it will be backed by a file pointing to os.devnull, i.e. you can write to it.

With {NONE}, you may e.g. get RuntimeError: lost sys.stdout in case it does get used; with {NULL} that never happens. However, some libraries handle this as input for their logging mechanism, and on Windows this is how you are compatible with pythonw.exe which is behaving like {NONE}.

Use Case 5 — Setuptools Wheels

If you have a, setup.cfg or pyproject.toml driven creation of wheels for your software in place, putting Nuitka to use is extremely easy.

Let’s start with the most common setuptools approach, you can, having Nuitka installed of course, simply execute the target bdist_nuitka rather than the bdist_wheel. It takes all the options and allows you to specify some more, that are specific to Nuitka.

# For if you don't use other build systems:
   # Data files are to be handled by setuptools and not Nuitka
   package_data={"some_package": ["some_file.txt"]},
   # This is to pass Nuitka options.
      'nuitka': {
         # boolean option, e.g. if you cared for C compilation commands
         '--show-scons': True,
         # options without value, e.g. enforce using Clang
         '--clang': None,
         # options with single values, e.g. enable a plugin of Nuitka
         '--enable-plugin': "pyside2",
         # options with several values, e.g. avoiding including modules
         '--nofollow-import-to' : ["*.tests", "*.distutils"],

# For with other build systems:
# The tuple nature of the arguments is required by the dark nature of
# "setuptools" and plugins to it, that insist on full compatibility,
# e.g. "setuptools_rust"

   # Data files are to be handled by setuptools and not Nuitka
   package_data={"some_package": ["some_file.txt"]},
   # This is to pass Nuitka options.
      'nuitka': {
         # boolean option, e.g. if you cared for C compilation commands
         '--show-scons': ("", True),
         # options without value, e.g. enforce using Clang
         '--clang': ("", None),
         # options with single values, e.g. enable a plugin of Nuitka
         '--enable-plugin': ("", "pyside2"),
         # options with several values, e.g. avoiding including modules
         '--nofollow-import-to' : ("", ["*.tests", "*.distutils"]),

If for some reason, you cannot or do not want to change the target, you can add this to your

# For


To temporarily disable the compilation, you could the remove above line, or edit the value to False by or take its value from an environment variable if you so choose, e.g. bool(os.getenv("USE_NUITKA", "True")). This is up to you.

Or you could put it in your setup.cfg

build_with_nuitka = true

And last, but not least, Nuitka also supports the new build meta, so when you have a pyproject.toml already, simple replace or add this value:

requires = ["setuptools>=42", "wheel", "nuitka", "toml"]
build-backend = "nuitka.distutils.Build"

# Data files are to be handled by setuptools and not Nuitka
some_package = ['data_file.txt']

# These are not recommended, but they make it obvious to have effect.

# boolean option, e.g. if you cared for C compilation commands, leading
# dashes are omitted
show-scons = true

# options with single values, e.g. enable a plugin of Nuitka
enable-plugin = "pyside2"

# options with several values, e.g. avoiding including modules, accepts
# list argument.
nofollow-import-to = ["*.tests", "*.distutils"]


For the nuitka requirement above absolute paths like C:\Users\...\Nuitka will also work on Linux, use an absolute path with two leading slashes, e.g. //home/.../Nuitka.


Whatever approach you take, data files in these wheels are not handled by Nuitka at all, but by setuptools. You can, however, use the data file embedding of Nuitka commercial. In that case, you actually would embed the files inside the extension module itself, and not as a file in the wheel.

Use Case 6 — Multidist

If you have multiple programs, that each should be executable, in the past you had to compile multiple times, and deploy all of these. With standalone mode, this, of course, meant that you were fairly wasteful, as sharing the folders could be done, but wasn’t really supported by Nuitka.

Enter Multidist. There is an option --main that replaces or adds to the positional argument given. And it can be given multiple times. When given multiple times, Nuitka will create a binary that contains the code of all the programs given, but sharing modules used in them. They therefore do not have to be distributed multiple times.

Let’s call the basename of the main path, and entry point. The names of these must, of course, be different. Then the created binary can execute either entry point, and will react to what sys.argv[0] appears to it. So if executed in the right way (with something like subprocess or OS API you can control this name), or by renaming or copying the binary, or symlinking to it, you can then achieve the miracle.

This allows to combine very different programs into one.


This feature is still experimental. Use with care and report your findings should you encounter anything that is undesirable behavior

This mode works with standalone, onefile, and mere acceleration. It does not work with module mode.

Use Case 7 — Building with GitHub Workflows

For integration with GitHub workflows there is this Nuitka-Action that you should use that makes it really easy to integrate. You ought to start with a local compilation though, but this will be easiest for cross platform compilation with Nuitka.

This is an example workflow that builds on all 3 OSes

      os: [macos-latest, ubuntu-latest, windows-latest]

   runs-on: ${{ matrix.os }}

      - name: Check-out repository
      uses: actions/checkout@v4

      - name: Setup Python
      uses: actions/setup-python@v5
         python-version: '3.10'
         cache: 'pip'
         cache-dependency-path: |

      - name: Install your Dependencies
      run: |
         pip install -r requirements.txt -r requirements-dev.txt

      - name: Build Executable with Nuitka
      uses: Nuitka/Nuitka-Action@main
         nuitka-version: main
         # many more Nuitka options available, see action doc, but it's best
         # to use nuitka-project: options in your code, so e.g. you can make
         # a difference for macOS and create an app bundle there.
         onefile: true

      - name: Upload Artifacts
      uses: actions/upload-artifact@v3
         name: ${{ runner.os }} Build
         path: | # match what's created for the 3 OSes

If your app is a GUI, e.g. should contain these comments as explained in Nuitka Project Options since on macOS this should then be a bundle.

# Compilation mode, standalone everywhere, except on macOS there app bundle
# nuitka-project-if: {OS} in ("Windows", "Linux", "FreeBSD"):
#    nuitka-project: --onefile
# nuitka-project-if: {OS} == "Darwin":
#    nuitka-project: --standalone
#    nuitka-project: --macos-create-app-bundle
# Debugging options, controlled via environment variable at compile time.
# nuitka-project-if: os.getenv("DEBUG_COMPILATION", "no") == "yes"
#     nuitka-project: --enable-console
# nuitka-project-else:
#     nuitka-project: --disable-console