我正在构建一个 Python 应用程序,不想强迫我的客户安装 Python 和模块。
那么,有没有办法将 Python 脚本编译为独立的可执行文件?
原文由 Jeff 发布,翻译遵循 CC BY-SA 4.0 许可协议
我正在构建一个 Python 应用程序,不想强迫我的客户安装 Python 和模块。
那么,有没有办法将 Python 脚本编译为独立的可执行文件?
原文由 Jeff 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用 PyInstaller 将 Python 程序打包为独立的可执行文件。它适用于 Windows、Linux 和 Mac。
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
仍在 Import-Erorr 中运行 - 尝试降级 pyinstaller - 请参阅 将 pynput 与 pyinstaller 一起使用时出现错误
有关更详细的演练,请参阅 手册。
原文由 Rumple Stiltskin 发布,翻译遵循 CC BY-SA 4.0 许可协议
2 回答5.2k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
4 回答1.4k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
2 回答864 阅读✓ 已解决
1 回答1.7k 阅读✓ 已解决
You can use py2exe as already answered and use Cython to convert your key
.py
files in.pyc
, C compiled files, like.dll
in Windows and.so
在 Linux 上。它比常见的
.pyo
和.pyc
文件更难还原(而且性能也有所提高!)。