Scroll to navigation

NUITKA-RUN(1) User Commands NUITKA-RUN(1)

NAME

nuitka-run - the Python compiler

SYNOPSIS

nuitka-run [options] main_module.py

OPTIONS

show program's version number and exit
show this help message and exit
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". You may also want to use "--python-flag=no_site" to avoid the "site.py" module, which can save a lot of code dependencies. 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 runtime warnings), "-O" (alias "no_asserts"), "no_docstrings" (do not use docstrings). 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 "scons" binary that is found in PATH, or a Python installation from Windows registry.
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.

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. 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 the content of that directory, no matter if it's used by the given main program in a visible form. Overrides all other recursion options. 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:

Also descend into imported modules from standard library. This will increase the compilation time by a lot. Defaults to off.
When --nofollow-imports is used, do not descend into any imported modules at all, overrides all other recursion options. Defaults to off.
When --follow-imports is used, attempt to descend into all imported modules. Defaults to 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.

Data files for standalone/onefile mode:

Include data files of the given package name. Can use patterns. By default Nuitka does not unless hard coded and vital for operation of a package. This will include all non-DLL, non-extension modules in the distribution. Default empty.
Include data files by filenames in the distribution. There are many allowed forms. With '--include-datafile=/path/to/file/*.txt=folder_name/some.txt' it will copy a single file and complain if it's multiple. With '--include-datafile=/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-file=/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-file' with patterns if you want non-recursive inclusion. An example would be '--include-datadir=/path/somedir=data/somedir' for plain copy, of the whole directory. All files are copied, if you want to exclude files you need to remove them beforehand. Default empty.

Immediate execution after compilation:

Execute immediately the created binary (or import the compiled module). Defaults to on.
Execute inside a debugger, e.g. "gdb" or "lldb" to automatically get a stack trace. Defaults to off.
When immediately executing the created binary (--execute), don't reset PYTHONPATH. When all modules are successfully included, you ought to not need PYTHONPATH anymore.

Dump options for internal tree:

Dump the final result of optimization as XML, then exit.

Code generation choices:

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. This is intended for tests only and should not be used for normal use.
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.

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 C files, object files, 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. 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.
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.
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.

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.
Enforce the use of specific MSVC version on Windows. Allowed values are e.g. 14.0, specify an illegal value for a list of installed compilers, beware that only latest MSVC is really supported. Defaults to the most recent version.
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".

PGO compilation choices:

Enables 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 highly experimental and not working with many 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:

Disable all information outputs, but show warnings. Defaults to off.
Operate Scons in non-quiet mode, showing the executed commands. Defaults to off.
Provide progress information and statistics. Defaults to off.
Disable progress bar outputs (if tqdm is installed). Defaults to off.
Provide memory information and statistics. Defaults to off.
Provide information for included modules and DLLs 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 --verbose, should be a filename. Default is standard output.

Windows specific controls:

When compiling for Windows, disable the console window. Defaults to off.
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.
Name of the company to use in Windows Version information. One of file or product version is required, when a version resource needs to be added, e.g. to specify product name, or company name. Defaults to unused.
Name of the product to use in Windows Version information. Defaults to base filename of the binary.
File version to use in Windows Version information. Must be a sequence of up to 4 numbers, nothing else allowed. One of file or product version is required, when a version resource needs to be added, e.g. to specify product name, or company name. Defaults to unused.
Product version to use in Windows Version information. Must be a sequence of up to 4 numbers, nothing else allowed. One of file or product version is required, when a version resource needs to be added, e.g. to specify product name, or company name. Defaults to unused.
Description of the file use in Windows Version information. One of file or product version is required, when a version resource needs to be added, e.g. to specify product name, or company name. Defaults to nonsense.
Use this as a temporary folder. Defaults to '%TEMP%\onefile_%PID%_%TIME%', i.e. system temporary directory.
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. Defaults to not active, use e.g. '%PROGRAM%.out.txt', i.e. file near your program.
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. Defaults to not active, use e.g. '%PROGRAM%.err.txt', i.e. file near your program.

macOS specific controls:

Add executable icon for binary to use. Can be given only one time. Defaults to Python icon if available.
When compiling for macOS, disable the console window and create a GUI application. Defaults to off.
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.
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 grant protected API accesses.
Name of the product to use in macOS bundle information. Defaults to base filename of the binary.

Linux specific controls:

Add executable icon for onefile binary to use. Can be given only one time. Defaults to Python icon if available.

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 --pluginlist to query the full list and exit. Default empty.
Plugins can detect if they might be used, and the you can disable the warning via --plugin-disable=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 plug-ins 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.
Write source changes to original Python files. Use with care. May need permissions, best for use in a virtualenv to debug if plugin code changes work with standard Python or to benefit from bloat removal even with pure Python. Default False.

Commercial: None Python: 2.7.16 (default, Oct 10 2019, 22:02:15) Executable: /usr/bin/python2 OS: Linux Arch: x86_64

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 --recurse-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 --recurse-all 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 --recurse-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 --unstriped --recurse-all 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 --recurse-all 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 --recurse-all some_program.py

Compile a Python program "some_program.py" and the plugins modules it loads at run time to an executable "some_program.exe":

$ nuitka --recurse-all --recurse-directory=plugins_dir some_program.py
October 2021 nuitka-run 0.6.17.2