综述
Python 可以将 代码编译打包成 可执行文件进行发布。
详细内容
Solution | Windows | Linux | OS X | Python 3 | License | One-file mode | Zipfile | import Eggs | pkg_resources support | Latest release dat |
---|---|---|---|---|---|---|---|---|---|---|
bbFreeze | yes | yes | yes | no | MIT | no | yes | yes | yes | Jan 20, 2014 |
py2exe | yes | no | no | yes | MIT | yes | yes | no | no | Oct 21, 2014 |
pyInstaller | yes | yes | yes | yes | GPL | yes | no | yes | no | Jul 9, 2019 |
cx_Freeze | yes | yes | yes | yes | PSF | no | yes | yes | no | Aug 29, 2019 |
py2app | no | no | yes | yes | MIT | no | yes | yes | yes | Mar 25, 2019 |
用于 python 打包的工具如上表所示,考虑到跨平台,因此考虑使用 pyinstaller
pyinstaller
原理
pyinstaller 会根据输入的 xx.py 分析创建打包配置脚本 xx.spec
然后根据 xx.spec 分析依赖打包文件
# win pyinstaller --add-data='src;dst' --distpath='distpath' test.py # 等同于 pyi-makespec --add-data='src;dst' test.py pyinstaller --disptpath='distpath' test.spec
Comments | NOTHING