Scroll to navigation

NUITKA(1) User Commands NUITKA(1)

NAME

nuitka - the Python compiler

SYNOPSIS

nuitka [--module] [--run] [options] main_module.py

OPTIONS

show this help message and exit
Show version information and important details for bug reports, then exit. Defaults to off.
Create an extension module executable instead of a program. Defaults to off.
Enable standalone mode for output. This allows you to transfer the created binary to other machines without it using an existing Python installation. This also means it will become big. It implies these option: "-- follow-imports" and "--python-flag=no_site". Defaults to off.
On top of standalone mode, enable onefile mode. This means not a folder, but a compressed executable is created and used. Defaults to off.
Use debug version or not. Default uses what you are using to run Nuitka, most likely a non-debug version.
Python flags to use. Default is what you are using to run Nuitka, this enforces a specific mode. These are options that also exist to standard Python executable. Currently supported: "-S" (alias "no_site"), "static_hashes" (do not use hash randomization), "no_warnings" (do not give Python run time warnings), "-O" (alias "no_asserts"), "no_docstrings" (do not use doc strings), "-u" (alias "unbuffered"), "isolated" (do not load outside code) and "-m" (package mode, compile as "package.__main__"). Default empty.
If using Python3.3 or Python3.4, provide the path of a Python binary to use for Scons. Otherwise Nuitka can use what you run Nuitka with or a Python installation from Windows registry. On Windows Python 3.5 or higher is needed. On non-Windows, Python 2.6 or 2.7 will do as well.
If specified once, this takes the place of the positional argument, i.e. the filename to compile. When given multiple times, it enables "multidist" (see User Manual) it allows you to create binaries that depending on file name or invocation name.
Control the inclusion of modules and packages in result:
Include a whole package. Give as a Python namespace, e.g. "some_package.sub_package" and Nuitka will then find it and include it and all the modules found below that disk location in the binary or extension module it creates, and make it available for import by the code. To avoid unwanted sub packages, e.g. tests you can e.g. do this "--nofollow-import-to=*.tests". Default empty.
Include a single module. Give as a Python namespace, e.g. "some_package.some_module" and Nuitka will then find it and include it in the binary or extension module it creates, and make it available for import by the code. Default empty.
Include also the code found in that directory, considering as if they are each given as a main file. Overrides all other inclusion options. You ought to prefer other inclusion options, that go by names, rather than filenames, those find things through being in "sys.path". This option is for very special use cases only. Can be given multiple times. Default empty.
Include into files matching the PATTERN. Overrides all other follow options. Can be given multiple times. Default empty.
For already compiled extension modules, where there is both a source file and an extension module, normally the extension module is used, but it should be better to compile the module from available source code for best performance. If not desired, there is --noprefer-source-code to disable warnings about it. Default off.
Control the following into imported modules:
Descend into all imported modules. Defaults to on in standalone mode, otherwise off.
Follow to that module if used, or if a package, to the whole package. Can be given multiple times. Default empty.
Do not follow to that module name even if used, or if a package name, to the whole package in any case, overrides all other options. Can be given multiple times. Default empty.
Do not descend into any imported modules at all, overrides all other inclusion options and not usable for standalone mode. Defaults to off.
Also descend into imported modules from standard library. This will increase the compilation time by a lot and is also not well tested at this time and sometimes won't work. Defaults to off.
Onefile options:
Use this as a folder to unpack to in onefile mode. Defaults to '%TEMP%/onefile_%PID%_%TIME%', i.e. user temporary directory and being non-static it's removed. Use e.g. a string like '%CACHE_DIR%/%COMPANY%/%PRODUCT%/%VERSION%' which is a good static cache path, this will then not be removed.
When stopping the child, e.g. due to CTRL-C or shutdown, etc. the Python code gets a "KeyboardInterrupt", that it may handle e.g. to flush data. This is the amount of time in ms, before the child it killed in the hard way. Unit is ms, and default 5000.
When creating the onefile, disable compression of the payload. This is mostly for debug purposes, or to save time. Default is off.
Data files:
Include data files for the given package name. DLLs and extension modules are not data files and never included like this. Can use patterns the filenames as indicated below. Data files of packages are not included by default, but package configuration can do it. This will only include non-DLL, non-extension modules, i.e. actual data files. After a ":" optionally a filename pattern can be given as well, selecting only matching files. Examples: "--includepackage-data=package_name" (all files) "--includepackage-data=package_name=*.txt" (only certain type) " --include-package-data=package_name=some_filename.dat (concrete file) Default empty.
Include data files by filenames in the distribution. There are many allowed forms. With '--include-datafiles=/path/to/file/*.txt=folder_name/some.txt' it will copy a single file and complain if it's multiple. With '--include-datafiles=/path/to/files/*.txt=folder_name/' it will put all matching files into that folder. For recursive copy there is a form with 3 values that '--includedata-files=/path/to/scan=folder_name=**/*.txt' that will preserve directory structure. Default empty.
Include data files from complete directory in the distribution. This is recursive. Check '--includedata-files' with patterns if you want non-recursive inclusion. An example would be '--include-datadir=/path/some_dir=data/some_dir' for plain copy, of the whole directory. All files are copied, if you want to exclude files you need to remove them beforehand, or use '--noinclude-data-files' option to remove them. Default empty.
Do not include data files matching the filename pattern given. This is against the target filename, not source paths. So to ignore a file pattern from package data for "package_name" should be matched as "package_name/*.txt". Or for the whole directory simply use "package_name". Default empty.
Output the data files found for a given package name. Default not done.
Metadata support:
Include metadata information for the given distribution name. Some packages check metadata for presence, version, entry points, etc. and without this option given, it only works when it's recognized at compile time which is not always happening. This of course only makes sense for packages that are included in the compilation. Default empty.
DLL files:
Do not include DLL files matching the filename pattern given. This is against the target filename, not source paths. So ignore a DLL "someDLL" contained in the package "package_name" it should be matched as "package_name/someDLL.*". Default empty.
Output the DLLs found for a given package name. Default not done.
Control the warnings to be given by Nuitka:
Enable warnings for implicit exceptions detected at compile time.
Enable warnings for unusual code detected at compile time.
Allow Nuitka to download external code if necessary, e.g. dependency walker, ccache, and even gcc on Windows. To disable, redirect input from nul device, e.g. "</dev/null" or "<NUL:". Default is to prompt.
Disable warning for a given mnemonic. These are given to make sure you are aware of certain topics, and typically point to the Nuitka website. The mnemonic is the part of the URL at the end, without the HTML suffix. Can be given multiple times and accepts shell pattern. Default empty.
Immediate execution after compilation:
Execute immediately the created binary (or import the compiled module). Defaults to off.
Execute inside a debugger, e.g. "gdb" or "lldb" to automatically get a stack trace. Defaults to off.
When immediately executing the created binary or module using '--run', don't reset 'PYTHONPATH' environment. When all modules are successfully included, you ought to not need PYTHONPATH anymore, and definitely not for standalone mode.
Compilation choices:
User provided Yaml file with package configuration. You can include DLLs, remove bloat, add hidden dependencies. Check User Manual for a complete description of the format to use. Can be given multiple times. Defaults to empty.
Enforce absolute compatibility with CPython. Do not even allow minor deviations from CPython behavior, e.g. not having better tracebacks or exception messages which are not really incompatible, but only different or worse. This is intended for tests only and should *not* be used.
Select what value "__file__" is going to be. With "runtime" (default for standalone binary mode and module mode), the created binaries and modules, use the location of themselves to deduct the value of "__file__". Included packages pretend to be in directories below that location. This allows you to include data files in deployments. If you merely seek acceleration, it's better for you to use the "original" value, where the source files location will be used. With "frozen" a notation "<frozen module_name>" is used. For compatibility reasons, the "__file__" value will always have ".py" suffix independent of what it really is.
Select what value "__name__" and "__package__" are going to be. With "runtime" (default for module mode), the created module uses the parent package to deduce the value of "__package__", to be fully compatible. The value "original" (default for other modes) allows for more static optimization to happen, but is incompatible for modules that normally can be loaded into any package.
Output choices:
Specify how the executable should be named. For extension modules there is no choice, also not for standalone mode and using it will be an error. This may include path information that needs to exist though. Defaults to '<program_name>' on this platform. .bin
Specify where intermediate and final output files should be put. The DIRECTORY will be populated with build folder, dist folder, binaries, etc. Defaults to current directory.
Removes the build directory after producing the module or exe file. Defaults to off.
Do not create a ".pyi" file for extension modules created by Nuitka. This is used to detect implicit imports. Defaults to off.
Debug features:
Executing all self checks possible to find errors in Nuitka, do not use for production. Defaults to off.
Keep debug info in the resulting object file for better debugger interaction. Defaults to off.
Enable vmprof based profiling of time spent. Not working currently. Defaults to off.
Create graph of optimization process internals, do not use for whole programs, but only for small test cases. Defaults to off.
Traced execution output, output the line of code before executing it. Defaults to off.
This is not incremental compilation, but for Nuitka development only. Takes existing files and simply compile them as C again. Allows compiling edited C files for quick debugging changes to the generated source, e.g. to see if code is passed by, values output, etc, Defaults to off. Depends on compiling Python source to determine which files it should look at.
Write the internal program structure, result of optimization in XML form to given filename.
Disable code aimed at making finding compatibility issues easier. This will e.g. prevent execution with "-c" argument, which is often used by code that attempts run a module, and causes a program to start itself over and over potentially. Default off.
Keep deployment mode, but disable selectively parts of it. Errors from deployment mode will output these identifiers. Default empty.
Use features declared as 'experimental'. May have no effect if no experimental features are present in the code. Uses secret tags (check source) per experimented feature.
Attempt to use less memory, by forking less C compilation jobs and using options that use less memory. For use on embedded machines. Use this in case of out of memory problems. Defaults to off.
Create a new virtualenv in that non-existing path from the report file given with e.g. '--report=compilationreport.xml'. Default not done.
Generate only C source code, and do not compile it to binary or module. This is for debugging and code coverage analysis that doesn't waste CPU. Defaults to off. Do not think you can use this directly.
Backend C compiler choice:
Enforce the use of clang. On Windows this requires a working Visual Studio version to piggy back on. Defaults to off.
Enforce the use of MinGW64 on Windows. Defaults to off unless MSYS2 with MinGW Python is used.
Enforce the use of specific MSVC version on Windows. Allowed values are e.g. "14.3" (MSVC 2022) and other MSVC version numbers, specify "list" for a list of installed compilers, or use "latest". Defaults to latest MSVC being used if installed, otherwise MinGW64 is used.
Specify the allowed number of parallel C compiler jobs. Defaults to the system CPU count.
Use link time optimizations (MSVC, gcc, clang). Allowed values are "yes", "no", and "auto" (when it's known to work). Defaults to "auto".
Use static link library of Python. Allowed values are "yes", "no", and "auto" (when it's known to work). Defaults to "auto".
Cache Control:
Disable selected caches, specify "all" for all cached. Currently allowed values are: "all","ccache","bytecode". can be given multiple times or with comma separated values. Default none.
Clean the given caches before executing, specify "all" for all cached. Currently allowed values are: "all","ccache","bytecode". can be given multiple times or with comma separated values. Default none.
Do not reuse dependency analysis results for modules, esp. from standard library, that are included as bytecode. Same as --disable-cache=bytecode.
Do not attempt to use ccache (gcc, clang, etc.) or clcache (MSVC, clangcl). Same as --disablecache=ccache.
PGO compilation choices:
Enables C level profile guided optimization (PGO), by executing a dedicated build first for a profiling run, and then using the result to feedback into the C compilation. Note: This is experimental and not working with standalone modes of Nuitka yet. Defaults to off.
Arguments to be passed in case of profile guided optimization. These are passed to the special built executable during the PGO profiling run. Default empty.
Command to execute when collecting profile information. Use this only, if you need to launch it through a script that prepares it to run. Default use created program.
Tracing features:
Report module, data files, compilation, plugin, etc. details in an XML output file. This is also super useful for issue reporting. These reports can e.g. be used to re-create the environment easily using it with '--create-environment-from-report', but contain a lot of information. Default is off.
Report data in diffable form, i.e. no timing or memory usage values that vary from run to run. Default is off.
Report data from you. This can be given multiple times and be anything in 'key=value' form, where key should be an identifier, e.g. use '--report-userprovided=pipenv-lock-hash=64a5e4' to track some input values. Default is empty.
Report via template. Provide template and output filename "template.rst.j2:output.rst". For built-in templates, check the User Manual for what these are. Can be given multiple times. Default is empty.
Disable all information outputs, but show warnings. Defaults to off.
Run the C building backend Scons with verbose information, showing the executed commands, detected compilers. Defaults to off.
Disable progress bars. Defaults to off.
Obsolete: Provide progress information and statistics. Disables normal progress bar. Defaults to off.
Provide memory information and statistics. Defaults to off.
Provide information for included modules and DLLs Obsolete: You should use '--report' file instead. Defaults to off.
Where to output '--show-modules', should be a filename. Default is standard output.
Output details of actions taken, esp. in optimizations. Can become a lot. Defaults to off.
Where to output from '--verbose', should be a filename. Default is standard output.
General OS controls:
When compiling for Windows or macOS, disable the console window and create a GUI application. Defaults to off.
When compiling for Windows or macOS, enable the console window and create a console application. This disables hints from certain modules, e.g. "PySide" that suggest to disable it. Defaults to true.
Force standard output of the program to go to this location. Useful for programs with disabled console and programs using the Windows Services Plugin of Nuitka commercial. Defaults to not active, use e.g. '%PROGRAM_BASE%.out.txt', i.e. file near your program, check User Manual for full list of available values.
Force standard error of the program to go to this location. Useful for programs with disabled console and programs using the Windows Services Plugin of Nuitka commercial. Defaults to not active, use e.g. '%PROGRAM_BASE%.err.txt', i.e. file near your program, check User Manual for full list of available values.
Windows specific controls:
Add executable icon. Can be given multiple times for different resolutions or files with multiple icons inside. In the later case, you may also suffix with #<n> where n is an integer index starting from 1, specifying a specific icon to be included, and all others to be ignored.
Copy executable icons from this existing executable (Windows only).
When compiling for Windows and onefile, show this while loading the application. Defaults to off.
Request Windows User Control, to grant admin rights on execution. (Windows only). Defaults to off.
Request Windows User Control, to enforce running from a few folders only, remote desktop access. (Windows only). Defaults to off.
macOS specific controls:
What architectures is this to supposed to run on. Default and limit is what the running Python allows for. Default is "native" which is the architecture the Python is run with.
When compiling for macOS, create a bundle rather than a plain binary application. Currently experimental and incomplete. Currently this is the only way to unlock disabling of console.Defaults to off.
Add icon for the application bundle to use. Can be given only one time. Defaults to Python icon if available.
Name of the application to use for macOS signing. Follow "com.YourCompany.AppName" naming results for best results, as these have to be globally unique, and will potentially grant protected API accesses.
Name of the product to use in macOS bundle information. Defaults to base filename of the binary.
Mode of application for the application bundle. When launching a Window, and appearing in Docker is desired, default value "gui" is a good fit. Without a Window ever, the application is a "background" application. For UI elements that get to display later, "ui-element" is in-between. The application will not appear in dock, but get full access to desktop when it does open a Window later.
When signing on macOS, by default an ad-hoc identify will be used, but with this option your get to specify another identity to use. The signing of code is now mandatory on macOS and cannot be disabled. Default "ad-hoc" if not given.
When signing for notarization, using a proper TeamID identity from Apple, use the required runtime signing option, such that it can be accepted.
Product version to use in macOS bundle information. Defaults to "1.0" if not given.
Request an entitlement for access to a macOS protected resources, e.g. "NSMicrophoneUsageDescription:Microphone access for recording audio." requests access to the microphone and provides an informative text for the user, why that is needed. Before the colon, is an OS identifier for an access right, then the informative text. Legal values can be found on https://developer.apple.com/doc umentation/bundleresources/information_property_list/p rotected_resources and the option can be specified multiple times. Default empty.
Linux specific controls:
Add executable icon for onefile binary to use. Can be given only one time. Defaults to Python icon if available.
Binary Version Information:
Name of the company to use in version information. Defaults to unused.
Name of the product to use in version information. Defaults to base filename of the binary.
File version to use in version information. Must be a sequence of up to 4 numbers, e.g. 1.0 or 1.0.0.0, no more digits are allowed, no strings are allowed. Defaults to unused.
Product version to use in version information. Same rules as for file version. Defaults to unused.
Description of the file used in version information. Windows only at this time. Defaults to binary filename.
Copyright used in version information. Windows only at this time. Defaults to not present.
Trademark used in version information. Windows only at this time. Defaults to not present.
Plugin control:
Enabled plugins. Must be plug-in names. Use '--pluginlist' to query the full list and exit. Default empty.
Disabled plugins. Must be plug-in names. Use '-- plugin-list' to query the full list and exit. Most standard plugins are not a good idea to disable. Default empty.
Plugins can detect if they might be used, and the you can disable the warning via "--disable-plugin=pluginthat-warned", or you can use this option to disable the mechanism entirely, which also speeds up compilation slightly of course as this detection code is run in vain once you are certain of which plugins to use. Defaults to off.
Show list of all available plugins and exit. Defaults to off.
The file name of user plugin. Can be given multiple times. Default empty.
Show source changes to original Python file content before compilation. Mostly intended for developing plugins. Default False.
Plugin options of 'anti-bloat':
Annotate what changes are by the plugin done.
What to do if a 'setuptools' or import is encountered. This package can be big with dependencies, and should definitely be avoided. Also handles 'setuptools_scm'.
What to do if a 'pytest' import is encountered. This package can be big with dependencies, and should definitely be avoided. Also handles 'nose' imports.
What to do if a unittest import is encountered. This package can be big with dependencies, and should definitely be avoided.
What to do if a IPython import is encountered. This package can be big with dependencies, and should definitely be avoided.
What to do if a 'dask' import is encountered. This package can be big with dependencies, and should definitely be avoided.
What to do if a 'numba' import is encountered. This package can be big with dependencies, and is currently not working for standalone. This package is big with dependencies, and should definitely be avoided.
This actually provides the default "warning" value for above options, and can be used to turn all of these on.
What to do if a specific import is encountered. Format is module name, which can and should be a top level package and then one choice, "error", "warning", "nofollow", e.g. PyQt5:error.

Commercial: None Python: 3.9.2 (default, Feb 28 2021, 17:03:44) Flavor: Debian Python Executable: /usr/bin/python3 OS: Linux Arch: x86_64 Distribution: Debian 11 Version C compiler: /usr/local/bin/gcc (gcc).

EXAMPLES

Compile a Python file "some_module.py" to a module "some_module.so":

$ nuitka --module some_module.py

Compile a Python program "some_program.py" to an executable "some_program.exe":

$ nuitka some_program.py

Compile a Python program "some_program.py" and the package "some_package" it uses to an executable "some_program.exe":

$ nuitka --follow-import--to=some_package some_program.py

Compile a Python program "some_program.py" and all the modules it uses to an executable "some_program.exe". Then execute it immediately when ready:

$ nuitka --run --follow-imports some_program.py

Compile a Python program "some_program.py" and the modules it uses (even standard library) to an executable "some_program.exe":

$ nuitka --recurse-all --follow-stdlib some_program.py

Compile a Python program "some_program.py" and the modules it uses to an executable "some_program.exe". Keep the debug information, so valgrind, gdb, etc. work nicely.

Note: This will *not* degrade performance:

$ nuitka --unstripped --follow-imports some_program.py

Compile a Python program "some_program.py" and the modules it uses to an executable "some_program.exe". Perform all kinds of checks about correctness of the generated C and run-time checks.

Note: This will degrade performance and should only be used to debug Nuitka:

$ nuitka --debug --follow-imports some_program.py

Compile a Python program "some_program.py" and the modules it uses to an executable "some_program.exe". Perform all kinds of checks about correctness of the generated C and run-time checks. Also use the debug Python library, which does its own checks.

Note: This will degrade performance and should only be used to debug Nuitka:

$ nuitka --debug --python-debug --follow-imports some_program.py
October 2023 nuitka 1.8.4