Can PyPy/RPython be used to produce a small standalone executable?

怎甘沉沦 提交于 2019-12-03 04:51:51

问题


(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.)


回答1:


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.



来源:https://stackoverflow.com/questions/4251964/can-pypy-rpython-be-used-to-produce-a-small-standalone-executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!