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

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

问题描述

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

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

推荐答案

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

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


Python源代码通过
CPython解释器自动编译为Python字节代码。编译代码是
,通常存储在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
文件。在最近的版本中,您可以
也创建一个包含
PY或PYC文件的ZIP存档,并使用一个小的
bootstrap脚本将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(跨平台)或Bob
Ippolito的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天全站免登陆