PyPy/RPython 可以用来生成小型独立可执行文件吗?
(或者,“PyPy/RPython 可以用来将 Python 编译/翻译为 C/C++ 而不需要 Python 运行时吗?”)
我尝试着理解 PyPy 及其 RPython 和 Python、它的运行和它的编译和翻译,都有些失败。
我有一个假设的 Python 项目(适用于 Windows);我希望将其大小缩小到一百千字节(ONO)的量级,而不是使用 py2exe 所需的几兆字节(在 UPX 之后)。我可以以任何方式使用 PyPy1 来生成不依赖于 Python26.dll 的独立可执行文件吗?如果可以的话,它是否需要遵循 RPython 限制,例如仅适用于内置类型,还是完整的 Python 语法?
我确实意识到,如果可以做到这一点,我几乎肯定无法直接使用 Python 中的 C 模块。
1 (自提问以来,情况已经变得更加清晰,工具链的这一部分更明确地标记为 RPython 而不是 PyPy;2010 年情况并非如此。)< /em>
(Or, "Can PyPy/RPython be used to compile/translate Python to C/C++ without requiring the Python runtime?")
I have tried to comprehend PyPy with its RPython and its Python, its running and its compiling and its translating, and have somewhat failed.
I have a hypothetical Python project (for Windows); I would like to keep its size down, in the order of a hundred kilobytes (O.N.O.) rather than the several megabytes that using py2exe entails (after UPX). Can I use PyPy1 in any way to produce a standalone executable which does not depend on Python26.dll? If I can, does it need to follow the RPython restrictions like for
only working on builtin types, or is it full Python syntax?
I do realise that if this can be done I almost certainly couldn't use C modules from Python directly.
1 (Since the time of asking, the situation has become clearer, and this part of the toolchain is more clearly branded as RPython rather than PyPy; it wasn't so in 2010.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,PyPy 可以从 RPython 代码生成独立的可执行文件。这意味着,在编写代码时,您需要遵循所有尴尬的 RPython 规则。您的 Python 代码完全不可能开箱即用,并且移植现有的 Python 代码通常并不有趣。它不会使可执行文件像 C 一样小,但例如使用 boehm GC 的 rpystone 目标(来自 pypy/translator/goal)在剥离后在 64 位上为 80k。
Yes, PyPy can produce standalone executables from RPython code. That means, you need to follow all the awkward RPython rules when it comes to writing code. Your Python code is completely unlikely to function out of the box and porting existing Python code is usually not fun. It won't make executables as small as C, but for example rpystone target (from pypy/translator/goal) using boehm GC is 80k on 64bit after stripping.