#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 简化的Windows构建脚本 专门解决PyInstaller依赖问题 """ import sys import subprocess import platform from pathlib import Path def create_simple_spec(): """创建简化的spec文件""" spec_content = '''# -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis( ['seat_allocation_system.py'], pathex=[], binaries=[], datas=[], hiddenimports=[ # 核心依赖 'pandas', 'openpyxl', 'numpy', 'datetime', 'pathlib', 'sys', 'os', # 修复关键错误 'numpy.core._methods', 'pandas._libs.window.aggregations', 'ctypes.util', 'pkg_resources.py2_warn', # pandas核心 'pandas._libs', 'pandas._libs.tslibs', 'pandas._libs.tslibs.base', 'pandas.io.excel', 'pandas.io.common', # numpy核心 'numpy.core', 'numpy.core.multiarray', 'numpy.core.umath', # openpyxl 'openpyxl.workbook', 'openpyxl.worksheet', 'openpyxl.styles', # 编码 'encodings.utf_8', 'encodings.gbk', ], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[ 'matplotlib', 'scipy', 'IPython', 'jupyter', 'tkinter', 'PyQt5', 'PyQt6', 'PIL', 'cv2', ], 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='座位分配系统', debug=False, bootloader_ignore_signals=False, strip=False, upx=False, upx_exclude=[], runtime_tmpdir=None, console=True, disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, ) ''' spec_file = Path('simple_build.spec') with open(spec_file, 'w', encoding='utf-8') as f: f.write(spec_content) print(f"✅ 创建spec文件: {spec_file}") return spec_file def build_exe(): """构建可执行文件""" print("=" * 60) print("简化Windows构建") print("=" * 60) # 检查环境 if platform.system() != 'Windows': print("❌ 此脚本仅适用于Windows") return False print(f"✅ 系统: {platform.system()} {platform.release()}") print(f"✅ Python: {sys.version}") # 检查主文件 main_file = Path('seat_allocation_system.py') if not main_file.exists(): print("❌ 未找到主程序文件") return False print(f"✅ 主程序: {main_file}") # 创建spec文件 spec_file = create_simple_spec() # 构建命令 cmd = [ sys.executable, '-m', 'PyInstaller', '--clean', '--noconfirm', str(spec_file) ] print(f"\n执行命令: {' '.join(cmd)}") print("开始构建...") try: # 执行构建 result = subprocess.run( cmd, capture_output=True, text=True, encoding='utf-8', errors='ignore' ) # 显示结果 if result.returncode == 0: print("✅ 构建成功!") # 检查生成的文件 exe_path = Path('dist/座位分配系统.exe') if exe_path.exists(): size_mb = exe_path.stat().st_size / (1024 * 1024) print(f"✅ 生成文件: {exe_path}") print(f"✅ 文件大小: {size_mb:.1f} MB") return True else: print("❌ 未找到生成的exe文件") return False else: print("❌ 构建失败!") print("错误输出:") print(result.stderr) return False except Exception as e: print(f"❌ 构建出错: {e}") return False def main(): """主函数""" success = build_exe() if success: print("\n🎉 构建完成!") print("可执行文件位置: dist/座位分配系统.exe") else: print("\n❌ 构建失败!") input("\n按Enter键退出...") if __name__ == '__main__': main()