将Python编译为本机代码? [英] Compiling Python to native code?

查看:158
本文介绍了将Python编译为本机代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

是否可以将Python编译成机器码?

可以将Python代码(及其依赖关系,加上解释器库)编译成单个本机 Windows可执行文件>没有 else捆绑在一起)从Python文件? (类似于Java的GNU编译器将Java编译成一个(可怕的)可执行文件,它包含真正的机器代码中的一切。)

Is it possible to compile Python code (plus its dependencies, plus the interpreter library) into a single, native Windows executable (with nothing else bundled along with it) from a Python file? (Kind of like how the GNU compiler for Java compiles Java into a native (humongous) executable, which contains everything in true machine code.)

要强调,我 一个自解压存档,一个可执行文件包或一些其他方式的欺骗通过捆绑文件内 exe - 我在找东西

To emphasize, I'm not asking for a "self-extracting archive", an "executable packer", or some other way of 'cheating' by bundling the files inside an exe -- I'm looking for something that genuinely converts Python into a native executable, like what GCJ does for Java.

只有如果上述不是可能:

至少可以从Python生成一个可执行文件包含解释器的代码以及所有库依赖关系,使得生成的可执行文件在运行之前不需要自动提取到目标磁盘上

Is it possible to at least generate a single executable from a Python code containing the interpreter bundled along with all the library dependencies, such that the resulting executable does not need to self-extract onto the target disk before running?

在这种情况下,'编译'需求是放松的:如果代码实际上被编译成机器代码(它可以简单地作为文本资源嵌入到目标可执行文件),这是没有关系的,但是结果必须是可以独立运行的单个 exe 文件,特别是不需要解压/安装任何东西。

In this scenario, the 'compilation' requirement is relaxed: it doesn't matter if the code is actually compiled into machine code (it could simply be embedded as a text resource into the target executable), but the result must nevertheless be a single exe file [and nothing else] that can run standalone, specifically without needing to unpack/install anything onto the target disk before running.

推荐答案

Shed Skin 可以将Python编译为C ++,但只能限制其子集。 Python的一些方面很难编译为本机代码。

Shed Skin can compile Python to C++, but only a restricted subset of it. Some aspects of Python are very difficult to compile to native code.

这篇关于将Python编译为本机代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆