Nuitka

Nuitka is a Python compiler written in Python.

Install Nuitka

  • python -m pip install nuitka

  • Verify using command python -m nuitka --version

Write some code and test

Create a folder for the Python code

  • mkdir HelloWorld
  • make a python file named hello.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def talk(message):
    return "Talk " + message


def main():
    print(talk("Hello World"))


if __name__ == "__main__":
    main()

Test your program

Do as you normally would. Running Nuitka on code that works incorrectly is not easier to debug.

1
python hello.py

Build it using

1
python -m nuitka hello.py

Note

This will prompt you to download a C caching tool (to speed up repeated compilation of generated C code) and a MinGW64 based C compiler, unless you have a suitable MSVC installed. Say yes to both those questions.

Run it

Execute the hello.exe created near hello.py.

参数

1
nuitka hello.py --onefile --standalone

--onefile 选项会将所有依赖打包进一个可执行文件中,--standalone 选项会确保该可执行文件在没有额外依赖的情况下运行。

参考