您可以使用pyinstaller 为您想要的不同平台创建可执行文件。
例如,
pyinstaller 命令的语法是:
pyinstaller [options] script [script ...] | specfile
在最简单的情况下,将当前目录设置为你的程序 myscript.py 的位置并执行:
pyinstaller myscript.py
PyInstaller 分析 myscript.py 并:
Writes myscript.spec in the same folder as the script.
Creates a folder build in the same folder as the script if it does not exist.
Writes some log files and working files in the build folder.
Creates a folder dist in the same folder as the script if it does not exist.
Writes the myscript executable folder in the dist folder.
在 dist 文件夹中,您可以找到分发给用户的捆绑应用程序。
通常你在命令行上命名一个脚本。如果您命名更多,则所有内容都会被分析并包含在输出中。但是,第一个名为的脚本提供了规范文件和可执行文件夹或文件的名称。它的代码在运行时首先执行。
对于某些用途,您可以编辑 myscript.spec 的内容(在使用规范文件中描述)。完成此操作后,将规范文件命名为 PyInstaller 而不是脚本:
pyinstaller myscript.spec
您可以给出脚本或规范文件的路径,例如
pyinstaller options... ~/myproject/source/myscript.py
或者,在 Windows 上,
pyinstaller "C:\Documents and Settings\project\myscript.spec"
pyinstaller