Nuitka (pronounced as ) is a
source-to-source compiler
A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler is a type of translator that takes the source code of a program written in a programming language as its input and produces an equivalent so ...
which compiles
Python code to
C source code, applying some compile-time optimizations in the process such as
constant folding and propagation, built-in call prediction,
type inference
Type inference, sometimes called type reconstruction, refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some bran ...
, and conditional statement execution.
Nuitka initially was designed to produce C++ code, but current versions produce C source code using only those features of
C11 that are shared by
C++03
C++03 is a version of the ISO/ IEC 14882 standard for the C++ programming language. It is defined by two standards organizations, the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC), in ...
, enabling further compilation to a binary executable format by modern C and C++ compilers including
gcc,
clang
Clang () is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, and the software frameworks OpenMP, OpenCL, RenderScript, CUDA, SYCL, and HIP. It acts as a drop-in replacement for the GNU Compiler ...
,
MinGW
MinGW ("Minimalist GNU for Windows"), formerly mingw32, is a free and open source software development environment to create Microsoft Windows applications.
MinGW includes a port of the GNU Compiler Collection (GCC), GNU Binutils for Windows ...
, or
Microsoft Visual C++
Microsoft Visual C++ (MSVC) is a compiler for the C, C++, C++/CLI and C++/CX programming languages by Microsoft. MSVC is proprietary software; it was originally a standalone product but later became a part of Visual Studio and made available i ...
. It accepts Python code compatible with several different Python versions (currently supporting versions 2.6, 2.7, and 3.3–3.12) and optionally allows for the creation of standalone programs that do not require Python to be installed on the target computer.
Nuitka was discussed at the 2012 EuroPython conference, and serious development began at the end of the same year. It now supports virtually all of the features of the Python language. Additional compile-time optimizations are planned for future releases, including avoiding the use of Python objects for additional variables whose type can be inferred at compile time, particularly when using iterators, which is expected to result in a large performance increase.
Limitations
Currently it is not possible to
cross-compile
A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. For example, a compiler that runs on a PC but generates code that runs on Android devices is a cross compil ...
binaries (e.g. building the executable on Windows and shipping it to macOS).
Standalone binaries built using the
--standalone
command line option include an embedded
CPython
CPython is the reference implementation of the Python programming language. Written in C and Python, CPython is the default and most widely used implementation of the Python language.
CPython can be defined as both an interpreter and a comp ...
interpreter to handle aspects of the language that are not determined when the program is compiled and must be interpreted at runtime, such as
duck typing
In computer programming, duck typing is an application of the duck test—"If it walks like a duck and it quacks like a duck, then it must be a duck"—to determine whether an object can be used for a particular purpose. With nominative ...
,
exception handling
In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
, and dynamic code execution (the
eval
function and
exec
function or statement), along with those Python and native libraries that are needed for execution, leading to rather large file sizes.
Nuitka's design heavily relies on the internals of the CPython interpreter, and as a result other implementations of the Python language such as
PyPy,
Jython
Jython is an implementation of the Python (programming language), Python programming language designed to run on the Java (programming language), Java platform. It was known as JPython until 1999.
Overview
Jython programs can import and use any ...
, and
IronPython cannot be used instead of CPython for the runtime interpreter and library.
Usage
Nuitka can be installed from the repositories of many Linux distributions. It can also be installed through
pip
and
pip3
, respectively. Compilation is done either with
nuitka program.py
or by calling Python itself and afterwards defining which module to run, which in this case is Nuitka (
python -m nuitka program.py
).
References
External links
*
* {{github, kayhayen/Nuitka - Source code and manual
Source-to-source compilers
Software using the Apache license
Python (programming language) implementations