具有 Linux 的所有依赖项的可执行 python 程序

Executable python program with all dependencies for Linux

有没有办法在 linux 系统上部署包含所有依赖项的 python 程序?我已经使用 py2exe 来 "compile" 一个 python 脚本,其中包含所有模块到一个独立的 .exe,但这显然只适用于 windows。 有没有简单的方法,例如使用 python 开发一个 flask 服务器并将其所有脚本和模块捆绑在一起,以便它可以在 Linux 上执行而无需使用 pip 安装依赖项? (假设 python3 安装在 Linux 平台上,但没有特定的 python 模块)。

谢谢!

您可以将依赖项安装在与提到的程序相同的目录中here,然后以任何您想要的方式打包。这样程序就可以始终访问依赖项,即使它们没有安装在程序正在执行的系统中。

在基于 Linux 的系统中使用 PyInstaller PyInstaller 是一个用于将 Python 脚本转换为独立的可部署应用程序的程序。

从 PyPI 安装 PyInstaller:

pip install pyinstaller

转到您的程序目录并 运行:

pyinstaller yourprogram.py

这将在名为 dist

的子目录中生成包

You can use -onefile argument in order to generate the bundle with only a single executable file.