将Python编译成机器码可行吗?

Is it feasible to compile Python to machine code?(将Python编译成机器码可行吗?)
本文介绍了将Python编译成机器码可行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

将 Python(可能通过中间 C 表示)编译成机器代码有多可行?

How feasible would it be to compile Python (possibly via an intermediate C representation) into machine code?

大概它需要链接到 Python 运行时库,并且 Python 标准库的任何部分(即 Python 本身)也需要编译(和链接).

Presumably it would need to link to a Python runtime library, and any parts of the Python standard library which were Python themselves would need to be compiled (and linked in) too.

此外,如果您想对表达式进行动态评估,则需要捆绑 Python 解释器,但也许不允许这样做的 Python 子集仍然有用.

Also, you would need to bundle the Python interpreter if you wanted to do dynamic evaluation of expressions, but perhaps a subset of Python that didn't allow this would still be useful.

它会提供任何速度和/或内存使用优势吗?推测 Python 解释器的启动时间将被消除(尽管共享库仍需要在启动时加载).

Would it provide any speed and/or memory usage advantages? Presumably the startup time of the Python interpreter would be eliminated (although shared libraries would still need loading at startup).

推荐答案

试试 ShedSkin Python-to-C++ 编译器,但它远非完美.如果只需要加速,还有 Psyco - Python JIT.但恕我直言,这是不值得的努力.对于代码的速度关键部分,最好的解决方案是将它们编写为 C/C++ 扩展.

Try ShedSkin Python-to-C++ compiler, but it is far from perfect. Also there is Psyco - Python JIT if only speedup is needed. But IMHO this is not worth the effort. For speed-critical parts of code best solution would be to write them as C/C++ extensions.

这篇关于将Python编译成机器码可行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Seasonal Decomposition of Time Series by Loess with Python(Loess 用 Python 对时间序列进行季节性分解)
Resample a time series with the index of another time series(使用另一个时间序列的索引重新采样一个时间序列)
How can I simply calculate the rolling/moving variance of a time series in python?(如何在 python 中简单地计算时间序列的滚动/移动方差?)
How to use Dynamic Time warping with kNN in python(如何在python中使用动态时间扭曲和kNN)
Keras LSTM: a time-series multi-step multi-features forecasting - poor results(Keras LSTM:时间序列多步多特征预测 - 结果不佳)
Python pandas time series interpolation and regularization(Python pandas 时间序列插值和正则化)