Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 579
Chris Morgan Avatar asked Nov 23 '10 01:11

Chris Morgan


People also ask

What is RPython for?

RPython is the language used to create PyPy. Technically, it is considered a translation and support framework for implementing dynamic programming languages, separating the language specs from the implementation aspects.

Does PyPy use GIL?

Yes, PyPy has a GIL.

Is PyPy compatible with CPython?

Compatibility: PyPy is highly compatible with existing python code. It supports cffi, cppyy, and can run popular python libraries like twisted, and django. It can also run NumPy, Scikit-learn and more via a c-extension compatibility layer.

Does PyPy support Python 3?

PyPy only supports one version of Python 2 and Python 3, which are PyPy 2.7 and PyPy 3.6. If the code that is executed in PyPy is pure Python, then the speed offered by PyPy is usually noticeable. But if the code contains C extensions, such as NumPy, then PyPy might actually increase the time.


1 Answers

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.

like image 85
fijal Avatar answered Sep 23 '22 19:09

fijal