# -*- coding: utf-8 -*- """打包配置(PyInstaller 6.x) 产物:dist/入库分拣工作站/ (onedir,启动快;摄像头取帧子进程也靠这个 exe 分发) ├─ 入库分拣工作站.exe ├─ _internal/ 运行库 ├─ config.json 现场可直接改 ├─ 使用说明.txt └─ data/photos/ 卡片兜底图片 """ import os ROOT = os.path.abspath(SPECPATH) # noqa: F821 (PyInstaller 注入) HIDDEN = [ # 摄像头子进程是 runpy 动态加载的,静态分析看不到,必须显式声明 'core.evidence._cam_child', 'core.evidence._probe_child', # pywin32 / comtypes / 打印机 'win32com', 'win32com.client', 'pythoncom', 'pywintypes', 'win32print', 'win32api', 'win32con', 'win32job', 'win32event', 'comtypes', 'comtypes.client', 'comtypes.stream', 'pygrabber', 'pygrabber.dshow_graph', # 串口枚举 'serial.tools.list_ports', 'serial.tools.list_ports_windows', # 设备自动识别(在函数里 import,显式声明更保险) 'core.devices', 'core.handwrite', # Pillow 与 Tk 的衔接 'PIL._tkinter_finder', ] EXCLUDES = [ 'matplotlib', 'scipy', 'pandas', 'PyQt5', 'PyQt6', 'PySide2', 'PySide6', 'IPython', 'jupyter', 'notebook', 'nbconvert', 'pytest', 'sphinx', ] a = Analysis( [os.path.join(ROOT, 'main.py')], pathex=[ROOT], binaries=[], datas=[ # 首跑兜底用的默认配置(main.py 里 _ensure_config 复制到 exe 旁边) (os.path.join(ROOT, 'assets', 'config.default.json'), '.'), ], hiddenimports=HIDDEN, hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=EXCLUDES, noarchive=False, optimize=0, ) pyz = PYZ(a.pure) exe = EXE( pyz, a.scripts, [], exclude_binaries=True, name='入库分拣工作站', debug=False, bootloader_ignore_signals=False, strip=False, upx=False, console=False, # 现场不弹黑窗;崩溃写 data/crash.log + 弹窗 disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, icon=os.path.join(ROOT, 'assets', 'app.ico'), version=os.path.join(ROOT, 'assets', 'version_info.txt'), ) coll = COLLECT( exe, a.binaries, a.datas, strip=False, upx=False, upx_exclude=[], name='入库分拣工作站', )