diff --git a/BUILD_FIXES.md b/BUILD_FIXES.md index 43a9082..5cefbc1 100644 --- a/BUILD_FIXES.md +++ b/BUILD_FIXES.md @@ -26,16 +26,39 @@ ## 🚀 使用修复后的构建脚本 -### 1. 测试环境 +### 方法1: 简化构建(推荐) ```bash -python test_build.py +# Windows批处理 +build_simple.bat + +# 或直接运行Python脚本 +python simple_windows_build.py ``` -### 2. 运行构建 +### 方法2: 完整构建 ```bash +# 先测试环境 +python test_build.py + +# 运行完整构建 python windows_build.py ``` +## ⚠️ 重要修复 + +### PyInstaller选项冲突问题 +**问题**: `option(s) not allowed` 错误 +**原因**: 使用spec文件时不能同时使用某些命令行选项 +**解决**: 将所有配置写入spec文件,命令行只保留基本选项 + +```python +# ❌ 错误用法 +cmd = ['pyinstaller', '--collect-all=pandas', 'file.spec'] + +# ✅ 正确用法 +cmd = ['pyinstaller', '--clean', '--noconfirm', 'file.spec'] +``` + ## 📋 构建选项说明 ### PyInstaller命令行选项 diff --git a/build_simple.bat b/build_simple.bat new file mode 100644 index 0000000..443685a --- /dev/null +++ b/build_simple.bat @@ -0,0 +1,31 @@ +@echo off +chcp 65001 >nul +echo ============================================================ +echo 简化Windows构建脚本 +echo ============================================================ +echo. + +echo 检查Python环境... +python --version +if errorlevel 1 ( + echo ❌ Python未安装或未添加到PATH + pause + exit /b 1 +) + +echo. +echo 检查依赖包... +python -c "import pandas, numpy, openpyxl, PyInstaller; print('✅ 所有依赖已安装')" +if errorlevel 1 ( + echo ❌ 缺少必要的依赖包 + echo 正在安装依赖... + pip install pandas numpy openpyxl pyinstaller +) + +echo. +echo 开始构建... +python simple_windows_build.py + +echo. +echo 构建完成! +pause diff --git a/simple_windows_build.py b/simple_windows_build.py new file mode 100644 index 0000000..bedf621 --- /dev/null +++ b/simple_windows_build.py @@ -0,0 +1,196 @@ +#!/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() diff --git a/windows_build.py b/windows_build.py index 6755366..d8b1099 100644 --- a/windows_build.py +++ b/windows_build.py @@ -175,7 +175,7 @@ a = Analysis( 'openpyxl.cell', 'openpyxl.formatting', - # pandas相关 + # pandas相关 - 完整导入 'pandas.io.excel', 'pandas.io.common', 'pandas.io.parsers', @@ -191,17 +191,37 @@ a = Analysis( 'pandas._libs.hashtable', 'pandas._libs.algos', 'pandas._libs.index', + 'pandas._libs.lib', + 'pandas._libs.missing', + 'pandas._libs.parsers', + 'pandas._libs.reduction', + 'pandas._libs.reshape', + 'pandas._libs.sparse', + 'pandas._libs.testing', + 'pandas._libs.writers', - # numpy相关 + # numpy相关 - 完整导入 'numpy.core', 'numpy.core.multiarray', 'numpy.core.umath', 'numpy.core._methods', 'numpy.core._dtype_ctypes', 'numpy.core._internal', + 'numpy.core.numeric', + 'numpy.core.numerictypes', + 'numpy.core.function_base', + 'numpy.core.machar', + 'numpy.core.getlimits', + 'numpy.core.shape_base', 'numpy.lib.format', + 'numpy.lib.mixins', + 'numpy.lib.scimath', + 'numpy.lib.stride_tricks', 'numpy.random', 'numpy.random._pickle', + 'numpy.random.mtrand', + 'numpy.random._common', + 'numpy.random._generator', # 编码相关 'encodings', @@ -217,10 +237,10 @@ a = Analysis( 'pkg_resources.py2_warn', 'pkg_resources.markers', - # Jinja2相关(可能被某些依赖使用) - 'jinja2', - 'jinja2.ext', - 'markupsafe', + # Jinja2相关(可选,某些依赖可能需要) + # 'jinja2', + # 'jinja2.ext', + # 'markupsafe', # Windows特定模块(仅在Windows上可用) # 'win32api', @@ -324,18 +344,11 @@ exe = EXE( print("开始构建可执行文件") print("=" * 60) + # 使用spec文件时,只能使用基本选项 cmd = [ sys.executable, '-m', 'PyInstaller', '--clean', '--noconfirm', - '--log-level=INFO', - '--collect-all=pandas', - '--collect-all=numpy', - '--collect-all=openpyxl', - '--hidden-import=numpy.core._methods', - '--hidden-import=pandas._libs.window.aggregations', - '--hidden-import=ctypes.util', - '--hidden-import=pkg_resources.py2_warn', str(spec_file) ]