是否可以编译用 Python 编写的程序? [英] Is it possible to compile a program written in Python?

查看:25
本文介绍了是否可以编译用 Python 编写的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to the Python programming language. I was wondering if it is possible to compile a program to written in Python.

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

Is it possible to convert Python scripts to some lower level programming languages which then can be compiled to binary code?

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

A developer who is considering to code in Python might want to keep the possibility open to be able to go for binary distribution later.

推荐答案

我认为 编译 Python 代码 将是一个很好的起点:

I think Compiling Python Code would be a good place to start:

Python 源代码自动编译成 Python 字节码CPython 解释器.编译后的代码是通常存储在 PYC(或 PYO)文件中,并且在源是再生时更新,或在其他必要时.

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.

向以下人员分发程序已经安装了 Python,你可以运送 PY 文件或 PYC文件.在最近的版本中,您可以还创建一个 ZIP 存档,其中包含PY 或 PYC 文件,并使用一个小的引导脚本"添​​加该 ZIP归档到路径.

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.

将 Python 程序编译"为可执行文件,使用捆绑工具,例如作为 Gordon McMillan 的安装人员(替代下载)(跨平台),Thomas Heller 的py2exe (Windows),Anthony Tuininga 的cx_Freeze(跨平台),或 BobIppolito 的 py2app (Mac).这些工具将您的模块和数据文件放入某种存档文件,并创建一个自动设置的可执行文件事情解决了,以便导入模块从那个档案.有些工具可以将存档嵌入到可执行文件中自己.

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 编写的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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