来源:https://techmonger.github.io/82/pyinstaller-script-to-binary/
- 安装 PyInstaller
pip install pyinstaller --upgrade
- 假设有如下一个 python 文件:
hello.py
#!/usr/bin/env python3
print("Hello World")
- 使用如下命令打包文件
hello.py
pyinstaller hello.py --onefile
- 命令执行结束后,会会生成文件
./dist/hello
运行这个命令
./dist/hello
Hello World
注意⚠️:使用 --onefile
参数后,被打包的程序以及它依赖的库,都会被打包在一起,形成一个很大的二进制文件。