部署 Python 应用程序#

页面状态:

不完整

上次审查:

2021-8-24

概述#

支持多个硬件平台#

FIXME

Meaning: x86, x64, ARM, others?

For Python-only distributions, it *should* be straightforward to deploy on all
platforms where Python can run.

For distributions with binary extensions, deployment is major headache.  Not only
must the extensions be built on all the combinations of operating system and
hardware platform, but they must also be tested, preferably on continuous
integration platforms.  The issues are similar to the "multiple Python
versions" section above, not sure whether this should be a separate section.
Even on Windows x64, both the 32 bit and 64 bit versions of Python enjoy
significant usage.

操作系统打包和安装程序#

FIXME

- Building rpm/debs for projects
- Building rpms/debs for whole virtualenvs
- Building macOS installers for Python projects
- Building Android APKs with Kivy+P4A or P4A & Buildozer

Windows#

FIXME

- Building Windows installers for Python projects

Pynsist#

Pynsist 是一款工具,它将 Python 程序与 Python 解释器捆绑到一个基于 NSIS 的单一安装程序中。在大多数情况下,打包仅要求用户选择一个 Python 解释器版本并声明程序的依赖项。该工具为 Windows 下载指定的 Python 解释器,并将其与所有依赖项打包到一个 Windows 可执行安装程序中。

已安装的程序可以从安装程序添加到开始菜单的快捷方式启动。它使用其应用程序目录中安装的 Python 解释器,独立于计算机上的任何其他 Python 安装。

Pynsist 的一个巨大优势在于 Windows 包可以在 Linux 上构建。在 documentation 中有针对不同类型程序(控制台、GUI)的多个示例。该工具在 MIT 许可下发布。

应用程序包#

FIXME

- wheels kinda/sorta

Windows#

py2exe#

py2exe 是一个 distutils 扩展,它允许从 Python 脚本构建独立的 Windows 可执行程序(32 位和 64 位)。支持官方开发周期中包含的 Python 版本(参见 Python 分支状态)。py2exe 可以构建控制台可执行文件和 Windows(GUI)可执行文件。构建 Windows 服务和 DLL/EXE COM 服务器可能可行,但未得到积极支持。该 distutils 扩展在 MIT 许可和 Mozilla 公共许可证 2.0 下发布。

macOS#

py2app#

py2app 是一个 Python setuptools 命令,它允许你从 Python 脚本制作独立的 macOS 应用程序包和插件。请注意,py2app 必须在 macOS 上使用才能构建应用程序,它无法在其他平台上创建 Mac 应用程序。py2app 在 MIT 许可下发布。

Unix(包括 Linux 和 macOS)#

pex#

pex 是一个用于生成 .pex(Python 可执行文件)文件的库,这些文件是虚拟环境精神中的可执行 Python 环境。pex 是 PEP 441 中概述的思想的扩展,它使 Python 应用程序的部署变得像 cp 一样简单。pex 文件甚至可以包含多个特定于平台的 Python 分发,这意味着一个 pex 文件可以在 Linux 和 macOS 上移植。pex 在 Apache 许可证 2.0 下发布。

配置管理#

FIXME

puppet
salt
chef
ansible
fabric