V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
zxgngl
V2EX  ›  Python

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

  •  
  •   zxgngl · 2016-01-29 20:30:22 +08:00 · 7590 次点击
    这是一个创建于 3009 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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!

    10 条回复    2016-01-31 22:10:12 +08:00
    Kilerd
        1
    Kilerd  
       2016-01-29 20:33:43 +08:00
    跟 py2exe 有什么区别?
    zxgngl
        2
    zxgngl  
    OP
       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
        3
    zxgngl  
    OP
       2016-01-29 20:44:40 +08:00
    @Kilerd 好像 py2exe 只支持 Windows 。
    zxgngl
        4
    zxgngl  
    OP
       2016-01-29 20:50:29 +08:00
    $ du -h ./Hello.exe
    92K
    Kilerd
        5
    Kilerd  
       2016-01-29 21:19:13 +08:00
    @zxgngl 就是是 92K 也要 带上运行库啊 也就是 你所说的 libpython ,就不止 92K 了吧
    zxgngl
        6
    zxgngl  
    OP
       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
        7
    icedx  
       2016-01-29 22:20:50 +08:00
    nightv2
        8
    nightv2  
       2016-01-30 08:38:55 +08:00 via Android
    pyinstall 打包为一个文件不是更好一些么
    Karblue
        9
    Karblue  
       2016-01-30 10:16:34 +08:00 via Android
    libpython 加上其他打包的 python 运行库。体积还不如 py2exe
    bear330
        10
    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 的話)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3192 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:35 · PVG 21:35 · LAX 06:35 · JFK 09:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.