python - 是否可以编译用 Python 编写的程序?

标签 python compilation

我是 Python 编程语言的新手。我想知道是否可以编译一个用 Python 编写的程序。

是否可以将 Python 脚本转换为一些较低级别的编程语言,然后编译为二进制代码?

考虑使用 Python 编写代码的开发人员可能希望保持开放的可能性,以便以后能够进行二进制分发。

最佳答案

我认为 Compiling Python Code将是一个很好的起点:

Python source code is automatically compiled into Python byte code by the CPython interpreter. Compiled code is usually stored in PYC (or PYO) files, and is regenerated when the source is updated, or when otherwise necessary.

To distribute a program to people who already have Python installed, you can ship either the PY files or the PYC files. In recent versions, you can also create a ZIP archive containing PY or PYC files, and use a small “bootstrap script” to add that ZIP archive to the path.

To “compile” a Python program into an executable, use a bundling tool, such as Gordon McMillan’s installer (alternative download) (cross-platform), Thomas Heller’s py2exe (Windows), Anthony Tuininga’s cx_Freeze (cross-platform), or Bob Ippolito’s py2app (Mac). These tools puts your modules and data files in some kind of archive file, and creates an executable that automatically sets things up so that modules are imported from that archive. Some tools can embed the archive in the executable itself.

关于python - 是否可以编译用 Python 编写的程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1957054/

相关文章:

java - 通过命令行编译但不是在 ant 中

python - 在 Python 中使用 Dateutil 时提取某些日期格式失败

python - Tensorflow U-Net 多类标签

python - Pandas :计算数字并结合应用的结果

c - 构建项目存在哪些替代环境?

使用 .lst 文件编译

python - 为什么我可以将元素分配给没有 setter 的列表?

python - 这两种测试方法的区别

linux - 获取未编译项目的智能感知数据

java - 动态编译语言 vs 静态编译语言