NUITKA-RUN(1)
๐ธ NUITKA-RUN(1) โ the Python compiler ๐ธ
Okay bestie, welcome to the manual for nuitka-run โ yes, it's the Python compiler, and it's lowkey iconic ๐
๐ NAME ๐
nuitka-run โ the Python compiler
โจ SYNOPSIS โจ
nuitka-run [options] main_module.py
๐ OPTIONS ๐
Here's the whole menu of flags, no cap. Every single one, we're not skipping a thing ๐
--helpโ shows you this exact help message and then bounces. That's it.--versionโ spills the version info plus all the important deets for bug reports, then exits. Defaults to off.--moduleโ makes an extension module executable instead of a regular program. Defaults to off.--standaloneโ turns on standalone mode for the output. This means you can yeet the created binary to other machines and it won't need an existing Python installation. It also means the thing gets big. It implies these options:-- follow-importsand--python-flag=no_site. Defaults to off.--onefileโ on top of standalone mode, turns on onefile mode. So instead of a folder, you get a compressed executable that's created and used. Defaults to off.--python-debugโ use the debug version or not. The default is whatever you're using to run Nuitka, which is most likely a non-debug version.--python-flag=FLAGโ Python flags to use. The default is whatever you're using to run Nuitka โ this forces a specific mode. These are options that also exist for the standard Python executable. Currently supported:-S(aliasno_site),static_hashes(do not use hash randomization),no_warnings(do not give Python run time warnings),-O(aliasno_asserts),no_docstrings(do not use doc strings),-u(aliasunbuffered) and-m. Default empty.--python-for-scons=PATHโ if you're on Python3.3 or Python3.4, give the path of a Python binary to use for Scons. Otherwise Nuitka can use whatever you run Nuitka with, or a Python installation from the Windows registry. On Windows you need Python 3.5 or higher. On non-Windows, Python 2.6 or 2.7 will do as well.
๐ Control the inclusion of modules and packages in result ๐
--include-package=PACKAGEโ includes a whole package. Give it as a Python namespace, e.g.some_package.sub_package, and Nuitka will find it, include it, and pull in all the modules under that disk location into the binary or extension module it makes, making them available for import by the code. To avoid unwanted sub packages, like tests, you can do e.g.--nofollow-import-to=*.tests. Default empty.--include-module=MODULEโ includes a single module. Give it as a Python namespace, e.g.some_package.some_module, and Nuitka will find it and include it in the binary or extension module it makes, making it available for import by the code. Default empty.--include-plugin-directory=MODULE/PACKAGEโ also includes the code found in that directory, treating each as if it were given as a main file. Overrides all other inclusion options. You really ought to prefer other inclusion options that go by names rather than filenames โ those find things by being insys.path. This option is for very special use cases only. Can be given multiple times. Default empty.--include-plugin-files=PATTERNโ include into files matching the PATTERN. Overrides all other follow options. Can be given multiple times. Default empty.--prefer-source-codeโ for already compiled extension modules where there's both a source file and an extension module, normally the extension module gets used, but it's better to compile from the available source code for best performance. If you don't want that, there's--noprefer-source-codeto disable warnings about it. Default off.
๐ฆ Control the following into imported modules ๐ฆ
--follow-importsโ descends into all imported modules. Defaults to on in standalone mode, otherwise off.--follow-import-to=MODULE/PACKAGEโ follows to that module if used, or if it's a package, to the whole package. Can be given multiple times. Default empty.--nofollow-import-to=MODULE/PACKAGEโ does not follow to that module name even if it's used, or if it's a package name, to the whole package in any case โ this overrides all other options. Can be given multiple times. Default empty.--nofollow-importsโ does not descend into any imported modules at all. Overrides all other inclusion options and isn't usable for standalone mode. Defaults to off.--follow-stdlibโ also descends into imported modules from the standard library. This will increase compilation time by a lot, and it's also not well tested at this time and sometimes won't work. Defaults to off.
๐ Onefile options ๐
--onefile-tempdir-spec=ONEFILE_TEMPDIR_SPECโ use this as the folder to unpack to in onefile mode. Defaults to'%TEMP%/onefile_%PID%_%TIME%', i.e. the user temporary directory, and since it's non-static it gets removed. You could use e.g. a string like'%CACHE_DIR%/%COMPANY%/%PRODUCT%/%VERSION%'which is a good static cache path โ that one will then not be removed.
๐ Data files ๐
--include-package-data=PACKAGEโ includes data files for the given package name. DLLs and extension modules are not data files and are never included like this. You can use patterns for 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:, you can optionally give a filename pattern too, 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=DESCโ includes 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's a form with 3 values,'--includedata-files=/path/to/scan=folder_name=**/*.txt', that will preserve directory structure. Default empty.--include-data-dir=DIRECTORYโ includes data files from a 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 a plain copy of the whole directory. All files are copied; if you want to exclude files you need to remove them beforehand, or use the'--noinclude-data-files'option to remove them. Default empty.--noinclude-data-files=PATTERNโ 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", it should be matched as"package_name/*.txt". Or for the whole directory, simply use"package_name". Default empty.
๐ง DLL files ๐ง
--noinclude-dlls=PATTERNโ do not include DLL files matching the filename pattern given. This is against the target filename, not source paths. So to ignore a DLL"someDLL"contained in the package"package_name", it should be matched as"package_name/someDLL.*". Default empty.--list-package-dlls=LIST_PACKAGE_DLLSโ outputs the DLLs found for a given package name. Default not done.
๐ Control the warnings to be given by Nuitka ๐
--warn-implicit-exceptionsโ enables warnings for implicit exceptions detected at compile time.--warn-unusual-codeโ enables warnings for unusual code detected at compile time.--assume-yes-for-downloadsโ lets Nuitka download external code if necessary, e.g. dependency walker, ccache, and even gcc on Windows. To disable, redirect input from the nul device, e.g."</dev/null"or"<NUL:". Default is to prompt.--nowarn-mnemonic=MNEMONICโ disables warning for a given mnemonic. These are given to make sure you're 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 โญ
--runโ executes the created binary immediately (or imports the compiled module). Defaults to on.--debuggerโ executes inside a debugger, e.g."gdb"or"lldb", to automatically get a stack trace. Defaults to off.--execute-with-pythonpathโ when immediately executing the created binary or module using'--run', don't reset the'PYTHONPATH'environment. When all modules are successfully included, you ought to not need PYTHONPATH anymore, and definitely not for standalone mode.
๐ซถ Compilation choices ๐ซถ
--user-package-configuration-file=YAML_FILENAMEโ a user-provided Yaml file with package configuration. You can include DLLs, remove bloat, add hidden dependencies. Check the User Manual for a complete description of the format to use. Can be given multiple times. Defaults to empty.--full-compatโ enforces 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.--file-reference-choice=MODEโ selects 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 deduce 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 to use the"original"value, where the source file's location is used. With"frozen", a notation"<frozen module_name>"is used. For compatibility reasons, the"__file__"value will always have a".py"suffix independent of what it really is.--module-name-choice=MODEโ this is the one that decides what__name__and__package__are gonna be, and honestly it's giving โจ identity crisis โจ energy. With"runtime"(which is the default for module mode), the created module uses the parent package to figure out__package__, so it's fully compatible. The value"original"(the default for other modes) lets more static optimization happen, but it's incompatible for modules that normally can be loaded into any package. pick your fighter ๐
๐พ Output choices ๐พ
--output-filename=FILENAMEโ tells Nuitka how the executable should be named. For extension modules there is no choice, and also not for standalone mode โ using it there is an error bestie. You can include path info in it, but that path needs to already exist tho. Defaults to'<program_name>'on this platform..bin๐ซถ--output-dir=DIRECTORYโ where the intermediate and final output files get dumped. ThatDIRECTORYis gonna get filled with the build folder, dist folder, binaries, etc. Defaults to the current directory. ๐ธ--remove-outputโ nukes the build directory after it's done producing the module or exe file. Defaults to off. ๐๏ธ--no-pyi-fileโ do not create a.pyifile for extension modules made by Nuitka. This file is what's used to detect implicit imports. Defaults to off. ๐
๐ Debug features ๐
--debugโ runs all the self checks possible to hunt down errors in Nuitka. Do not use for production. Defaults to off. (devs only, iykyk ๐)--unstrippedโ keeps debug info in the resulting object file so your debugger interaction is nicer. Defaults to off. ๐--profileโ enables vmprof based profiling of time spent. Not working currently. Defaults to off. ๐ญ--internal-graphโ creates a graph of the optimization process internals. Do not use for whole programs, only for small test cases. Defaults to off. ๐--trace-executionโ traced execution output: it prints the line of code before executing it. Defaults to off. ๐--recompile-c-onlyโ this is not incremental compilation, it's for Nuitka development only, periodt. It takes existing files and simply compiles them as C again. It lets you compile 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. ๐งช--xml=XML_FILENAMEโ writes the internal program structure and the result of optimization in XML form to the given filename. ๐--generate-c-onlyโ generates only C source code, and does 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. ๐--experimental=FLAGโ uses 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. ๐ฌ--low-memoryโ tries to use less memory by forking fewer C compilation jobs and using options that use less memory. For use on embedded machines. Use this if you're hitting out of memory problems. Defaults to off. ๐ง
๐ง Backend C compiler choice ๐ง
--clangโ forces the use of clang. On Windows this requires a working Visual Studio version to piggy back on. Defaults to off. ๐ฆ--mingw64โ forces the use of MinGW64 on Windows. Defaults to off unless MSYS2 with MinGW Python is used. ๐ช--msvc=MSVC_VERSIONโ forces the use of a specific MSVC version on Windows. Allowed values are e.g."14.3"(MSVC 2022) and other MSVC version numbers โ or specify"list"for a list of installed compilers, or use"latest". Defaults to latest MSVC being used if installed, otherwise MinGW64 is used. ๐--jobs=Nโ sets the allowed number of parallel C compiler jobs. Defaults to the system CPU count. โก--lto=choiceโ use link time optimizations (MSVC, gcc, clang). Allowed values are"yes","no", and"auto"(when it's known to work). Defaults to"auto". ๐ฅ--static-libpython=choiceโ use the static link library of Python. Allowed values are"yes","no", and"auto"(when it's known to work). Defaults to"auto". ๐
๐๏ธ Cache Control ๐๏ธ
--disable-cache=DISABLED_CACHESโ disables 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-cache=CLEAN_CACHESโ cleans 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. ๐งผ--disable-bytecode-cacheโ do not reuse dependency analysis results for modules โ esp. from the standard library โ that are included as bytecode. Same as--disable-cache=bytecode. ๐ง--disable-ccacheโ do not attempt to use ccache (gcc, clang, etc.) or clcache (MSVC, clangcl). Same as--disablecache=ccache. ๐ซ
๐ PGO compilation choices ๐
--pgoโ 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. ๐ฌ--pgo-args=PGO_ARGSโ arguments to be passed in case of profile guided optimization. These get passed to the special built executable during the PGO profiling run. Default empty. ๐จ--pgo-executable=PGO_EXECUTABLEโ the 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 the created program. ๐โโ๏ธ
๐ Tracing features ๐
--report=REPORT_FILENAMEโ reports module, data files, compilation, plugin, etc. details in an XML output file. This is also super useful for issue reporting. Default is off. ๐--quietโ disables all information outputs, but still shows warnings. Defaults to off. ๐คซ--show-sconsโ runs the C building backend Scons with verbose information, showing the executed commands and detected compilers. Defaults to off. ๐ ๏ธ--no-progressbarโ disables progress bars. Defaults to off. ๐--show-progressโ Obsolete: provide progress information and statistics. Disables the normal progress bar. Defaults to off. ๐--show-memoryโ provides memory information and statistics. Defaults to off. ๐ง--show-modulesโ provides information for included modules and DLLs. Obsolete: you should use the'--report'file instead. Defaults to off. ๐ฆ--show-modules-output=PATHโ where to output'--show-modules'; should be a filename. Default is standard output. ๐ค--verboseโ outputs details of actions taken, esp. in optimizations. Can become a lot. Defaults to off. ๐ฃ๏ธ--verbose-output=PATHโ where to output from'--verbose'; should be a filename. Default is standard output. ๐ฅ
๐ฅ๏ธ General OS controls ๐ฅ๏ธ
--disable-consoleโ when compiling for Windows or macOS, disables the console window and creates a GUI application. Defaults to off. ๐ช--enable-consoleโ when compiling for Windows or macOS, enables the console window and creates a console application. This disables hints from certain modules, e.g."PySide", that suggest to disable it. Defaults to true. โ--force-stdout-spec=FORCE_STDOUT_SPECโ forces standard output of the program to go to this location. Useful for programs with a disabled console and programs using the Windows Services Plugin of Nuitka commercial. Defaults to not active โ use e.g.'%PROGRAM%.out.txt', i.e. a file near your program. ๐--force-stderr-spec=FORCE_STDERR_SPECโ forces standard error of the program to go to this location. Useful for programs with a disabled console and programs using the Windows Services Plugin of Nuitka commercial. Defaults to not active โ use e.g.'%PROGRAM%.err.txt', i.e. a file near your program. ๐
๐ช Windows specific controls ๐ช
--windows-icon-from-ico=ICON_PATHโ adds an executable icon. Can be given multiple times for different resolutions or files with multiple icons inside. In the latter case, you may also suffix with#<n>wherenis an integer index starting from1, specifying a specific icon to be included, and all others to be ignored. ๐จ--windows-icon-from-exe=ICON_EXE_PATHโ copies executable icons from this existing executable (Windows only). ๐ฏ--onefile-windows-splash-screen-image=SPLASH_SCREEN_IMAGEโ when compiling for Windows and onefile, shows this while loading the application. Defaults to off. ๐ผ๏ธ--windows-uac-adminโ requests Windows User Control to grant admin rights on execution. (Windows only). Defaults to off. ๐ฎ--windows-uac-uiaccessโ requests Windows User Control to enforce running from a few folders only, and remote desktop access. (Windows only). Defaults to off. ๐
๐ macOS specific controls ๐
--macos-target-arch=MACOS_TARGET_ARCHโ what architectures this is 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. ๐๏ธ--macos-create-app-bundleโ when compiling for macOS, creates 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. ๐ฆ--macos-app-icon=ICON_PATHโ adds an icon for the application bundle to use. Can be given only one time. Defaults to the Python icon if available. ๐--macos-signed-app-name=MACOS_SIGNED_APP_NAMEโ name of the application to use for macOS signing. Follow"com.YourCompany.AppName"naming for best results, as these have to be globally unique, and will potentially grant protected API accesses. โ๏ธ--macos-app-name=MACOS_APP_NAMEโ name of the product to use in macOS bundle information. Defaults to the base filename of the binary. ๐--macos-app-mode=MODEโ bestie, this is the whole vibe of your app bundle. When you're launching a Window and you want it showing up in Docker (yes, literally "Docker", that's what it says ๐), the default value"gui"is your girl. If your app never opens a Window at all, it's a"background"application. And for UI elements that only get to show up later?"ui-element"is the in-between queen โ she won't appear in the dock, but she gets full access to the desktop the moment she does open a Window later. ๐--macos-sign-identity=MACOS_APP_VERSIONโ so when you sign on macOS, by default an ad-hoc identity gets used, but with this option you get to specify a whole other identity to use. Signing code is mandatory on macOS now and it cannot be disabled, periodt. Default is"ad-hoc"if you don't give anything. ๐--macos-sign-notarizationโ when you're signing for notarization using a proper TeamID identity from Apple, flip this on so the required runtime signing option gets used, meaning it can actually be accepted. ๐--macos-app-version=MACOS_APP_VERSIONโ the product version that goes into your macOS bundle information. Defaults to"1.0"if you don't say otherwise. โจ--macos-app-protected-resource=RESOURCE_DESCโ this one requests an entitlement for access to a macOS protected resource. Like, e.g."NSMicrophoneUsageDescription:Microphone access for recording audio."asks for microphone access and gives the user an informative little text about why on earth that's needed. Before the colon you put an OS identifier for the access right, then the informative text after it. You can find legal values athttps://developer.apple.com/documentation/bundleresources/information_property_list/protected_resourcesand you can specify this option multiple times. Default is empty. ๐ค
๐ง Linux specific controls ๐ง
--linux-icon=ICON_PATHโ adds an executable icon for the onefile binary to use. Can be given only one time, so don't get greedy. Defaults to the Python icon if it's available. ๐ผ๏ธ
๐ฆ Binary Version Information ๐ฆ
--company-name=COMPANY_NAMEโ the name of the company used in version information. Defaults to unused.--product-name=PRODUCT_NAMEโ the name of the product used in version information. Defaults to the base filename of the binary.--file-version=FILE_VERSIONโ the file version used in version information. It must be a sequence of up to 4 numbers, e.g.1.0or1.0.0.0โ no more digits allowed, no strings allowed, no exceptions bestie. Defaults to unused. โ ๏ธ--product-version=PRODUCT_VERSIONโ the product version used in version information. Same rules as for file version, so don't try anything cute. Defaults to unused.--file-description=FILE_DESCRIPTIONโ a description of the file used in version information. Windows only at this time. Defaults to the binary filename.--copyright=COPYRIGHT_TEXTโ copyright used in version information. Windows only at this time. Defaults to not present.--trademarks=TRADEMARK_TEXTโ copyright used in version information. Windows only at this time. Defaults to not present.
๐ Plugin control ๐
--enable-plugin=PLUGIN_NAMEโ enabled plugins. Must be plug-in names. Use--pluginlistto query the full list and exit. Default empty.--disable-plugin=PLUGIN_NAMEโ disabled plugins. Must be plug-in names. Use-- plugin-listto query the full list and exit. Most standard plugins are not a good idea to disable, so like, be careful. Default empty.--plugin-no-detectionโ plugins can detect if they might be used, and then 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, because that detection code is running in vain once you're already certain which plugins you want. Defaults to off.--plugin-listโ show the list of all available plugins and exit. Defaults to off.--user-plugin=PATHโ the file name of a user plugin. Can be given multiple times. Default empty.--show-source-changesโ show source changes to the original Python file content before compilation. Mostly intended for developing plugins. DefaultFalse.
๐ Plugin options of 'anti-bloat' ๐
--show-anti-bloat-changesโ annotate what changes are done by the plugin.--noinclude-setuptools-mode=NOINCLUDE_SETUPTOOLS_MODEโ what to do if a'setuptools'import is encountered. This package can be big with dependencies, and should definitely be avoided. Also handles'setuptools_scm'.--noinclude-pytest-mode=NOINCLUDE_PYTEST_MODEโ 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.--noinclude-unittest-mode=NOINCLUDE_UNITTEST_MODEโ what to do if aunittestimport is encountered. This package can be big with dependencies, and should definitely be avoided.--noinclude-IPython-mode=NOINCLUDE_IPYTHON_MODEโ what to do if anIPythonimport is encountered. This package can be big with dependencies, and should definitely be avoided.--noinclude-dask-mode=NOINCLUDE_DASK_MODEโ what to do if a'dask'import is encountered. This package can be big with dependencies, and should definitely be avoided.--noinclude-numba-mode=NOINCLUDE_NUMBA_MODEโ what to do if a'numba'import is encountered. This package can be big with dependencies, and it's currently not working for standalone. Should definitely be avoided, fr fr.--noinclude-default-mode=NOINCLUDE_DEFAULT_MODEโ this actually provides the default"warning"value for the above options, and can be used to turn all of them on.--noinclude-custom-mode=CUSTOM_CHOICESโ what to do if a specific import is encountered. The format is a module name, which can and should be a top level package, and then one choice:"error","warning","nofollow", e.g.PyQt5:error.
And here's the little system mood board it prints out, kept exactly as it comes ๐ :
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/lib/ccache/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
and that's the whole page bestie, you made it to the end ๐๐ซถ
This one's for nuitka-run version 1.3.5, dated January 2023 โ so if you're reading this in a different era, go check NUITKA-RUN(1) for the current tea. ๐โจ
๐ฆ where this page comes from
- ubuntu noble: nuitka 1.3.5+ds-1 ยท Apache+Nuitka_comment
- ubuntu resolute: nuitka 1.3.5+ds-1 ยท Apache+Nuitka_comment
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms