1. 命令行使用
pyinstaller.exe ../build_xxx.py -i "../app/xxx/res/yyy.ico" -p '../runtime/win32/python37/lib/;../runtime/win32/python37/libex/' -w
-i
: 图标文件;-p
: PythonPath,Python的库目录路径;-w
: Windows环境下,不启动命令行运行GUI程序;--name
-F
(--onefile
)--hidden-import
: 声明隐式导入的依赖包;--add-data
--add-binary
--exclude-module
2. spec文件,定义编译流
执行指令: pyinstaller xxx.spec
# -*- mode: python ; coding: utf-8 -*-
# pyinstaller.exe ../build_xxx.py -i "../app/xxx/res/yyy.ico" -p '../runtime/win32/python37/lib/;../runtime/win32/python37/libex/' -w
block_cipher = None
a = Analysis(['../build_demo.py'],
pathex=['../runtime/win64/Lib/site-packages'],
binaries=[],
datas=[
("../app/demo/view/ui", "app/demo/view/ui"),
],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='Demo',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
icon='../app/ocrkit/res/ocr.ico')
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='Demo')
pathex
: 同cmd -p
选项,对应PythonPath;datas
: 复制文件或文件夹;console
: 同cmd -w
选项;icon
: 同cmd -i
选项;