Compile PyPy to Exe

 ̄綄美尐妖づ 提交于 2019-12-30 01:35:10

问题


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 ?


回答1:


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.




回答2:


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)


来源:https://stackoverflow.com/questions/10470800/compile-pypy-to-exe

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