Python-to-C++ compiler promises speedier execution

Nuitka converts Python to C++, which can then be executed or packaged up as a stand-alone file for redistribution

C++ Java PHP .Net Python JavaScript code type input keyboard
Credit: Thinkstock

The more popular the language, the more varied its implementations. Python is a classic example, with most of the replacements for its default interpreter written to speed up execution of the language. Among the latest and most intriguing is Nuika.

Nuika (open source on GitHub) compiles Python to C++ code, which can then be executed in-place or packaged up as a stand-alone file for redistribution. Unlike some other replacements for existing Python interpreters, it claims full compatibility with all the language constructs in Python 2.6, 2.7, 3.2, and 3.3.

According to the project's lead, Kay Hayen, Nuitka's first milestone -- feature parity with the language -- has already been met. Hayen presented a discussion of Nuitka back at the EuroPython 2012 conference and work started in earnest (based on the GitHub commit history) around the end of that year.

To work its magic, Nuitka requires both a current version of the Python interpreter (2.x or 3.x branch) and a C++ compiler. Microsoft Visual Studio, MinGW, and Clang/LLVM are all supported for the latter, in both 32- and 64-bit editions. However, cross-compilation -- say, from Linux to Windows or vice-versa -- isn't supported, and compiling a 64-bit executable on Windows requires Microsoft's compiler.

Another drawback is the creation of stand-alone executables. To do this, Nuitka includes CPython's redistributables (in Windows, a collection of DLLs and other support files) with the executable. Consequently, stand-alone programs come with a fair amount of overhead: A simple "Hello, world" command-line script for Python 2.7 produces a 2.6MB 32-bit Windows executable, along with 7.4MB of support files. (A GUI version of the same program weighed in at 10MB for the executable, 20MB total.)

Still, what Nuitka can already accomplish is impressive, and Hayen's plans for its future are ambitious. The next steps are to make the code generated by Nuitka more efficient, including better handling of variable types and optimizations for control flow. Further out on the road map are even more sophisticated and valuable features, such as having Nuitka interface directly with C code used in Python via the language's ctypes foreign-function system.

From CIO: 8 Free Online Courses to Grow Your Tech Skills