我是 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/