NUITKA(1)
β¨ NAME β¨
nuitka β the Python compiler π
(and yes bestie, this is the NUITKA(1) page, filed under User Commands, so you're in exactly the right place π«Ά)
π SYNOPSIS π
nuitka [--module] [--run] [options] main_module.py
π OPTIONS π
--helpβ show this help message and exit. That's it, that's the whole vibe β¨--versionβ Show version information and important details for bug reports, then exit. Defaults to off. (<- screenshot this if you're filing a bug, fr fr)--moduleβ Create an extension module executable instead of a program. Defaults to off.--standaloneβ 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-importsand--python-flag=no_site. Defaults to off.--onefileβ On top of standalone mode, enable onefile mode. This means not a folder, but a compressed executable is created and used. Defaults to off.--python-debugβ Use debug version or not. Default uses what you are using to run Nuitka, most likely a non-debug version.--python-flag=FLAGβ 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(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 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.
π Control the inclusion of modules and packages in result π
--include-package=PACKAGEβ Include a whole package. Give as a Python namespace, e.g.some_package.sub_packageand 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-module=MODULEβ Include a single module. Give as a Python namespace, e.g.some_package.some_moduleand 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-plugin-directory=MODULE/PACKAGEβ 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 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 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-codeto disable warnings about it. Default off.
π Control the following into imported modules π
--follow-importsβ Descend into all imported modules. Defaults to on in standalone mode, otherwise off.--follow-import-to=MODULE/PACKAGEβ Follow to that module if used, or if a package, to the whole package. Can be given multiple times. Default empty.--nofollow-import-to=MODULE/PACKAGEβ 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.--nofollow-importsβ Do not descend into any imported modules at all, overrides all other inclusion options and not usable for standalone mode. Defaults to off.--follow-stdlibβ 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 π
--onefile-tempdir-spec=ONEFILE_TEMPDIR_SPECβ 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.
π¦ Data files π¦
--include-package-data=PACKAGEβ 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=DESCβ 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-dir=DIRECTORYβ 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.--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 forpackage_nameshould be matched aspackage_name/*.txt. Or for the whole directory simply usepackage_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 ignore a DLLsomeDLLcontained in the packagepackage_nameit should be matched aspackage_name/someDLL.*. Default empty.--list-package-dlls=LIST_PACKAGE_DLLSβ Output the DLLs found for a given package name. Default not done.
β Control the warnings to be given by Nuitka β
--warn-implicit-exceptionsβ Enable warnings for implicit exceptions detected at compile time.--warn-unusual-codeβ Enable warnings for unusual code detected at compile time.--assume-yes-for-downloadsβ 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/nullor<NUL:. Default is to prompt.--nowarn-mnemonic=MNEMONICβ 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 π₯
--runβ Execute immediately the created binary (or import the compiled module). Defaults to off.--debuggerβ Execute inside a debugger, e.g.gdborlldbto automatically get a stack trace. Defaults to off.--execute-with-pythonpathβ When immediately executing the created binary or module using--run, don't resetPYTHONPATHenvironment. 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β 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.--full-compatβ 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.
bestie. it literally says should not be used. it's for tests. that's the whole warning, don't @ me π
--file-reference-choice=MODEβ Select what value__file__is going to be. Withruntime(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 theoriginalvalue, where the source files location will be used. Withfrozena notation<frozen module_name>is used. For compatibility reasons, the__file__value will always have.pysuffix independent of what it really is.
--module-name-choice=MODEβ picks what__name__and__package__end up being. With"runtime"(that's the default for module mode), the module you made uses its parent package to figure out__package__, so it stays fully compatible. With"original"(default for all the other modes) you get way more static optimization to happen, but it's incompatible for modules that would normally be loadable into any package. Pick your fighter π
β¨ Output choices β¨
--output-filename=FILENAMEβ tells Nuitka what your executable should be called. Bestie, for extension modules there is no choice, and it's the same story for standalone mode β using it there is just an error. You can include path info in it, but that path has to actually exist. Defaults to<program_name>.binon this platform.--output-dir=DIRECTORYβ says where the intermediate and final output files go.DIRECTORYgets populated with the build folder, the dist folder, binaries, all of it. Defaults to the current directory.--remove-outputβ yeets the build directory once the module or exe file has been produced. Defaults to off.--no-pyi-fileβ don't create a".pyi"file for the extension modules Nuitka made. That file is what's used to detect implicit imports. Defaults to off.
π Debug features π
--debugβ runs every self check possible to hunt down errors in Nuitka itself. Do not use this for production. Defaults to off.--unstrippedβ keeps the debug info in the resulting object file so your debugger plays nicer with you. Defaults to off.--profileβ enables vmprof-based profiling of time spent. Not working currently. Defaults to off.--internal-graphβ makes a graph of the optimization process internals. Do not use this on whole programs, only for small test cases. Defaults to off.--trace-executionβ traced execution output, so it prints the line of code right before running it. Defaults to off.--recompile-c-onlyβ okay so this is not incremental compilation, it's for Nuitka development only. It takes existing files and simply compiles them as C again. That lets you compile edited C files for quick debugging changes to the generated source β like, to see if code is passed by, values output, etc. Defaults to off. It depends on compiling Python source to figure out which files it should look at.--xml=XML_FILENAMEβ writes the internal program structure and the result of optimization in XML form to the filename you give it.--generate-c-onlyβ generates only C source code and does not compile it to a 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β use features declared as'experimental'. May have no effect if there are no experimental features 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. Made for embedded machines. Use this if you're hitting out-of-memory problems. Defaults to off.
π₯ Backend C compiler choice π₯
--clangβ enforces the use of clang. On Windows this needs a working Visual Studio version to piggy back on. Defaults to off.--mingw64β enforces the use of MinGW64 on Windows. Defaults to off, unless you're on MSYS2 with MinGW Python.--msvc=MSVC_VERSIONβ enforces the use of a specific MSVC version on Windows. Allowed values are e.g."14.3"(MSVC 2022) and other MSVC version numbers. Specify"list"to get a list of installed compilers, or use"latest". Defaults to the latest MSVC being used if it's installed, otherwise MinGW64 is used.--jobs=Nβ specifies 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 the selected caches; specify"all"for all of them. 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 of them. 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 β especially ones 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 feeding that result back 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 pass 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. Only use this if you need to launch it through a script that prepares it to run. Default is to use the created program.
π Tracing features π
--report=REPORT_FILENAMEβ reports module, data files, compilation, plugin, etc. details into an XML output file. This one 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 the detected compilers. Defaults to off.--no-progressbarβ disables progress bars. Defaults to off.--show-progressβ obsolete: provides 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, especially 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 disabling it. Defaults to true.--force-stdout-spec=FORCE_STDOUT_SPECβ forces the 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 the 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 for files with multiple icons inside. In the latter 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 the 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, 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, since 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β sets the vibe of your app bundle. when you're launching a window and wanna show up in the Docker, the default"gui"is a good fit. no window ever? that's a"background"app. for UI elements that get to display later,"ui-element"is the in-between. the app won't appear in dock, but bestie it gets full access to the desktop when it opens a window later. π--macos-sign-identity=MACOS_APP_VERSIONβ when signing on macOS, by default an ad-hoc identify (their spelling, not mine π) gets used, but with this option you get to specify another identity to use. code signing is mandatory on macOS now and cannot be disabled. default is"ad-hoc"if not given. π--macos-sign-notarizationβ when signing for notarization using a proper TeamID identity from Apple, use the required runtime signing option so it can be accepted. β--macos-app-version=MACOS_APP_VERSIONβ product version to use in macOS bundle information. defaults to"1.0"if not given. π¦--macos-app-protected-resource=RESOURCE_DESCβ request an entitlement for access to a macOS protected resource. like"NSMicrophoneUsageDescription:Microphone access for recording audio."requests access to the mic and provides informative text for the user about why it's needed. before the colon is an OS identifier for an access right, then the informative text. legal values can be found athttps://developer.apple.com/documentation/bundleresources/information_property_list/protected_resourcesand this option can be specified multiple times. default is empty. π‘οΈ
π§ Linux specific controls: π§
--linux-icon=ICON_PATHβ add executable icon for onefile binary to use. can be given only one time. defaults to Python icon if available. π
π¦ Binary Version Information: π¦
--company-name=COMPANY_NAMEβ name of the company to use in version information. defaults to unused. π’--product-name=PRODUCT_NAMEβ name of the product to use in version information. defaults to base filename of the binary. π·οΈ--file-version=FILE_VERSIONβ file version to use in version information. must be a sequence of up to 4 numbers, e.g.1.0or1.0.0.0, no more digits are allowed, no strings are allowed. defaults to unused. π’--product-version=PRODUCT_VERSIONβ product version to use in version information. same rules as for file version. defaults to unused. π’--file-description=FILE_DESCRIPTIONβ description of the file used in version information. Windows only at this time. defaults to 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 (yes, copyright, not trademarks, we don't make the rules π). 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. 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. this also speeds up compilation slightly because the detection code is run in vain once you are certain of which plugins to use. defaults to off. β‘--plugin-listβ show 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 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'or 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 a unittest import is encountered. this package can be big with dependencies, and should definitely be avoided. π«--noinclude-IPython-mode=NOINCLUDE_IPYTHON_MODEβ what to do if an IPython import 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 is currently not working for standalone. this package is big with dependencies, and should definitely be avoided. π«--noinclude-default-mode=NOINCLUDE_DEFAULT_MODEβ this actually provides the default"warning"value for above options, and can be used to turn all of these on. β οΈ--noinclude-custom-mode=CUSTOM_CHOICESβ what to do if a specific import is encountered. format is module name, which can and should be a top level package, then one choice:"error","warning","nofollow", e.g.PyQt5:error. π―
and just so you know, the build info is: Commercial: None Python: 2.7.18 (default, Jul 14 2021, 08:11:37) Flavor: Debian Python Executable: /usr/bin/python2 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 a wrap, bestie! you just absorbed the whole NUITKA(1) man page for nuitka 1.3.5, dated January 2023. now go compile something iconic and remember: the vibe is immaculate, the facts are exact. πβ¨π¦
π¦ 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