I know how to compile CPython file to exe using cx_freeze but is it possible to compile a simple program using PyPy to Exe ?
-
1possible duplicate of http://stackoverflow.com/questions/4251964/can-pypy-be-used-to-produce-a-small-standalone-executable – Roland Smith May 06 '12 at 15:07
-
1It's not a duplicate becouse that link You provided solves nothing and is outdated 2010, now we have 2012. Maybe something was changed since that time. – Nuncjo May 06 '12 at 15:22
-
7@RolandSmith That question specifically asks about something *unlike* py2exe et al, in that it does not include the Python interpreter, and accepted "Stop writing Python and start using this totally different language which happens to be a subset of Python" as answer. This question simply asks for a similar freezing tool that works with PyPy and full Python. – May 06 '12 at 15:41
-
2It should be possible, since (very recently) embedding PyPy became possible: http://mail.python.org/pipermail/pypy-dev/2012-April/009726.html. So all it would take is a wrapper exe that also hosts the zipped library and scripts. Any takers? – TryPyPy May 14 '12 at 05:03
-
I think this is bogus, you are using interpreted language and for that to work you should have interpreter. Embedding it into single executable is nonsense in long-run. Either get something that converts your code to let's say C or next time make wiser choice of language before writing project. Not that what you ask for is impossible, it's just wrong. – Tomas Pruzina May 25 '12 at 10:11
-
6@AoeAoe What the heck? Your statements betray great confusion and/or misunderstanding. (1) Interpreted/compiled is not a property of programming language, it's a property of programming language implementations. Any language can be both compiled and interpreted, including Python. (2) Converting code to some other language (say, C) is precisely the definition of a compiler. (3) The whole point of tools like the ones discussed here is leveraging the existing interpreters for executable production. [I could go on with minor points, but comment space is running out.] – May 25 '12 at 13:00
-
Possible duplicate of [Can PyPy/RPython be used to produce a small standalone executable?](http://stackoverflow.com/questions/4251964/can-pypy-rpython-be-used-to-produce-a-small-standalone-executable) – Cees Timmerman May 18 '17 at 15:37
2 Answers
There is no ready-made way or tutorial on how to do create an EXE from a program using the PyPy interpreter, as far as i know. And it's not exactly trivial to get things going, i am afraid.
In principle, there are two ways to consider for using PyPy's translations to get a EXE file, either using the PyPy interpreter or writing your own RPython program (The PyPy interpreter is itself an RPython program, i.e. using a restricted subset of Python).
If you program uses a restricted subset of RPython and no dependencies, you could look into using the translate script in pypy/translator/goal where you'll also find a lot of target*.py files. Take one and modify it for your purposes. You might first want to play with translating python functions starting from here:
http://doc.pypy.org/en/latest/getting-started-dev.html#trying-out-the-translator
If you program is an application and depends on external packages, you should first try to make sure that your program works on pypy at all - not all external libraries are supported. You might then look into modifying the targetpypystandalone script to load your application modules. If in doubt, try to get some help on the pypy-dev mailing list or the #pypy channel on irc.freenode.net.

- 21,501
- 4
- 47
- 53
-
One downside of RPython is that it's undocumented, and if your code doesn't happen to follow it, the translator will fail with completely incomprehensible error messages. (For example, trying to use a named tuple gives the error FrozenDesc object has no attribute allenforced_attrs.) – Antimony Jul 05 '12 at 01:39
-
@hpk42 After 2013, we can use `pypy/rpython/bin/rpython` to translate. Also, [the RPython doc](https://rpython.readthedocs.io/en/latest/index.html) is available. – nekketsuuu Mar 23 '18 at 04:04
This is a py2exe solution that might work for you: compile.py
#!/usr/bin/env python
# Corey Goldberg
from distutils.core import setup
import py2exe
import sys
if len(sys.argv) == 2:
entry_point = sys.argv[1]
sys.argv.pop()
sys.argv.append('py2exe')
sys.argv.append('-q')
else:
print 'usage: compile.py <python_script>\n'
raw_input('press ENTER to exit...')
sys.exit(1)
opts = {
'py2exe': {
'compressed': 1,
'optimize': 2,
'bundle_files': 1
}
}
setup(console=[entry_point], options=opts, zipfile=None)

- 17,623
- 11
- 91
- 124

- 1,141
- 1
- 17
- 38
-
6-1 py2exe does *not* work with PyPy (at least not currently) - please do some research first. And why do you link to some obscure project's setup script rather than to the py2exe project? – May 25 '12 at 13:14
-
1@delnan: Because py2exe doesn't produce a single file as output unless you tell it to by the options secumind linked to. – Cees Timmerman May 30 '12 at 15:02
-
1@CeesTimmerman Surely this option, along with others that may be useful to OP, is documented somewhere. – May 30 '12 at 15:08
-
3@delnan: Practical answers are encouraged here. Surely people can paste "py2exe" into their search bar. – Cees Timmerman May 30 '12 at 15:10
-
@CeesTimmerman Your comments only addressed the second part of delnan's comment, so this still fails to be a "practical answer". In any case, I agree with delnan. It is better to describe the solution fully in the answer than to merely provide a link to another site (which could break at any point). – JBentley Mar 28 '14 at 19:21
-
1In addition to it being likely that this approach does not work, the link is broken – Diomedea Sep 21 '21 at 14:06