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

use*_*097 3 python linux py2exe python-3.x

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

谢谢!

小智 6

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

从 PyPI 安装 PyInstaller:

pip install pyinstaller
Run Code Online (Sandbox Code Playgroud)

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

pyinstaller yourprogram.py
Run Code Online (Sandbox Code Playgroud)

这将在名为 dist 的子目录中生成包

您可以使用-onefile参数来生成只有一个可执行文件的包。

  • 在 Windows 上时,pyinstaller 会在 /dist 目录中创建 .exe。我怎样才能告诉它以Linux为目标? (2认同)
  • 我用一个简单的 helloWorld.py 对其进行了测试。当尝试在 Linux 上运行可执行文件时,我收到此错误:´ File "site-packages/PyInstaller/loader/rthooks/pyi_rth__tkinter.py", line 30, in <module> FileNotFoundError: Tcl data directory "/var/folders/ 3q/wfnfkkm976z8q9gjz_npccbh0000gp/T/_MEIafCy5q/tcl”未找到。[20445] 无法执行脚本 pyi_rth__tkinter´ (2认同)