PyInstaller 快速入门

将 Python 程序合并为单个文件

目录

使用 PyInstaller
Python 程序打包为独立的可执行文件。它适用于 Linux、Windows 和 Mac。

虽然不是最有效的方式,但可以使用。

Python cube
这张 Python 立方体图片是由 AI 模型 Flux 1 dev 生成的。

PyInstaller 快速入门

从 PyPI 安装 PyInstaller

pip install pyinstaller

进入你的程序目录并运行:

pyinstaller yourprogram.py

这将生成一个名为 dist 的子目录中的打包文件。

pyinstaller -F yourprogram.py

添加 -F(或 –onefile)参数会将所有内容打包成一个单独的“exe”文件。

pyinstaller -F --paths=<your_path>\Lib\site-packages  yourprogram.py

如果遇到“ImportError”,可以考虑使用侧边库。

pip install pynput==1.6.8
仍然出现 ImportError - 尝试降级 PyInstaller - 请参阅使用 pynput 与 PyInstaller 时出现错误

缺点

有很多人抱怨加载速度慢……请自行进一步研究。

有用的链接