Nuitka - 直接将 Python 程序编译生成可执行的 exe 文件

2016-01-29 20:30:22 +08:00
 zxgngl

http://nuitka.net/

我举个例子:

$ curl -LO http://nuitka.net/releases/Nuitka-0.5.18.1.tar.gz
$ tar xf Nuitka-0.5.18.1.tar.gz
$ echo 'print "Hello, Nuitka!"' > Hello.py
$ ./Nuitka-0.5.18.1/bin/nuitka Hello.py
$ chmod +x hello.exe
$ ./Hello.exe
Hello, Nuitka!

7594 次点击
所在节点    Python
10 条回复
Kilerd
2016-01-29 20:33:43 +08:00
跟 py2exe 有什么区别?
zxgngl
2016-01-29 20:42:14 +08:00
It translates the Python into a C level program that then uses "libpython" to execute in the same way as CPython does.
zxgngl
2016-01-29 20:44:40 +08:00
@Kilerd 好像 py2exe 只支持 Windows 。
zxgngl
2016-01-29 20:50:29 +08:00
$ du -h ./Hello.exe
92K
Kilerd
2016-01-29 21:19:13 +08:00
@zxgngl 就是是 92K 也要 带上运行库啊 也就是 你所说的 libpython ,就不止 92K 了吧
zxgngl
2016-01-29 21:45:48 +08:00
@Kilerd 是呀,是呀。 14M 啊。

$ ./Nuitka-0.5.18.1/bin/nuitka --standalone Hello.py
$ du -h ./Hello.dist/
14M ./Hello.dist/
icedx
2016-01-29 22:20:50 +08:00
nightv2
2016-01-30 08:38:55 +08:00
pyinstall 打包为一个文件不是更好一些么
Karblue
2016-01-30 10:16:34 +08:00
libpython 加上其他打包的 python 运行库。体积还不如 py2exe
bear330
2016-01-31 22:10:12 +08:00
它的重點應該不是打包吧, 而是它會把你的 python code 轉成直接用 python 的 c API 形式的 c++程式碼, 然後給 c++編譯器去編譯, 好處是可以在幾乎 100%的相容性上得到 static compiler 的優化能力, 例如你的 python 函數寫:
def f(i):
return i + 1 + 20
f(100)
在轉成對應的 c++ code 編譯後, 就可以直接把 1 + 20 換成 21, 甚至把 f(100)這行整個直接 inline 了, 進而優化整個程式的效能, 卻保持程式相容性 (不像 pypy 要舍棄一些相容性, 如果用到 c extension 的話)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/254314

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX