Conda 可以为你的应用创建一个单独的环境,可以避免不必要的包被打包,减少包的体积大小.
创建环境:
# 创建新环境
conda create -n build_to_binary python=3.9 -y
# 激活新环境
conda activate build_to_binary
安装依赖:
# 安装 PyInstaller
pip install pyinstaller
# 或者 Nuitka
pip install nuitka
# 安装其他的依赖
pip install xxx
文件夹模式便于分发和调试。运行速度还可以。
pyinstaller \
--onedir \
--name=app-name \
--clean \
main.py
单文件模式启动较慢。
pyinstaller \
--onefile \
--name=app-name \
--clean \
main.py
第一次运行会比较慢,后来都很快。
nuitka \
--standalone \
--follow-imports \
--show-progress \
--output-dir=dist \
--output-filename=app-name \
--remove-output \
main.py
跟 PyInstaller 的 onefile 一样,启动都是很慢的。
nuitka \
--onefile \
--standalone \
--follow-imports \
--output-dir=dist \
--output-filename=app-name \
--remove-output \
main.py