使用PyInstaller 把 python 代码打包成二进制文件

创建日期: 2023-07-07 15:07 | 作者: 风波 | 浏览次数: 14 | 分类: Python

来源:https://techmonger.github.io/82/pyinstaller-script-to-binary/

  1. 安装 PyInstaller
pip install pyinstaller --upgrade
  1. 假设有如下一个 python 文件:hello.py
#!/usr/bin/env python3
print("Hello World")
  1. 使用如下命令打包文件 hello.py
pyinstaller hello.py --onefile
  1. 命令执行结束后,会会生成文件 ./dist/hello 运行这个命令
./dist/hello
Hello World

注意⚠️:使用 --onefile 参数后,被打包的程序以及它依赖的库,都会被打包在一起,形成一个很大的二进制文件。

14 浏览
7 爬虫
0 评论