# -*- mode: python ; coding: utf-8 -*- """ PyInstaller 打包配置文件 用于打包 wrench_gui.py 为可执行文件 """ block_cipher = None import os # 获取当前脚本所在目录的父目录(项目根目录) # 这样 PyInstaller 可以找到 wrench_controller.py current_dir = os.path.dirname(os.path.abspath('wrench_gui.spec')) parent_dir = os.path.dirname(current_dir) a = Analysis( ['wrench_gui.py'], pathex=[ parent_dir, # 添加父目录到搜索路径,让 PyInstaller 能找到 wrench_controller.py current_dir, # 当前目录 ], binaries=[], datas=[ # 包含配置文件(如果程序需要读取) (os.path.join(parent_dir, 'config.json'), '.'), # 将 config.json 复制到可执行文件目录 ], hiddenimports=[ 'wrench_controller', 'device_manager', 'tkinter', 'tkinter.ttk', 'tkinter.messagebox', 'requests', 'json', 'threading', 'socket', 'struct', 'datetime', 'pathlib', ], hookspath=[], hooksconfig={}, 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, a.binaries, a.zipfiles, a.datas, [], name='wrench_gui', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=False, # 不显示控制台窗口(GUI应用) disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, icon=None, # 可以添加图标文件路径,如 'icon.ico' )