diff --git a/build_production.py b/build_production.py index 16130da..7af5c53 100644 --- a/build_production.py +++ b/build_production.py @@ -85,16 +85,7 @@ def main(): result = subprocess.run(['python', 'quick_build.py'], capture_output=False) if result.returncode == 0: - # 确保输出目录正确性 - if os.path.exists('dist/main') and not os.path.exists('dist/MultiPlatformGUI'): - print("🔄 修正输出目录名称...") - try: - os.rename('dist/main', 'dist/MultiPlatformGUI') - print("✅ 已重命名为: dist/MultiPlatformGUI/") - except Exception as e: - print(f"⚠️ 重命名失败: {e}") - - # 验证最终输出 + # 验证最终输出(quick_build.py 已统一输出到 MultiPlatformGUI) if os.path.exists('dist/MultiPlatformGUI'): print("\n🎉 生产环境打包成功!") print("📁 输出目录: dist/MultiPlatformGUI/") @@ -108,9 +99,7 @@ def main(): else: print("⚠️ 主程序文件未找到") else: - print("\n❌ 输出目录验证失败") - if os.path.exists('dist/main'): - print("💡 发现: dist/main/ 目录,请手动重命名为 MultiPlatformGUI") + print("\n❌ 输出目录验证失败: 未找到 dist/MultiPlatformGUI") else: print("\n❌ 打包失败") diff --git a/quick_build.py b/quick_build.py index d3bf358..9677739 100644 --- a/quick_build.py +++ b/quick_build.py @@ -53,7 +53,7 @@ def build_with_command(): cmd = [ 'pyinstaller', - '--name=main', + '--name=MultiPlatformGUI', # 直接使用最终目录名 '--onedir', # 相当于 --exclude-binaries '--windowed', # 相当于 -w '--icon=static/ai_assistant_icon_64.png', # 添加主程序图标 @@ -96,33 +96,32 @@ def build_with_command(): if result.returncode == 0: print("✅ 打包成功!") - print("📁 打包结果: dist/main/") + print("📁 打包结果: dist/MultiPlatformGUI/") - # 重命名目录为统一的输出路径 - if os.path.exists('dist/main'): + # 验证输出目录(不需要重命名了) + if os.path.exists('dist/MultiPlatformGUI/MultiPlatformGUI.exe'): + # PyInstaller 生成的 exe 名称是 MultiPlatformGUI.exe + # 重命名为 main.exe(保持兼容性) try: - # 如果目标目录已存在,先删除 - if os.path.exists('dist/MultiPlatformGUI'): - print("🗑️ 删除旧的 MultiPlatformGUI 目录...") - shutil.rmtree('dist/MultiPlatformGUI') + old_exe = 'dist/MultiPlatformGUI/MultiPlatformGUI.exe' + new_exe = 'dist/MultiPlatformGUI/main.exe' - # 重命名 - os.rename('dist/main', 'dist/MultiPlatformGUI') - print("✅ 已重命名为: dist/MultiPlatformGUI/") + if os.path.exists(new_exe): + os.remove(new_exe) - # 验证重命名结果 - if os.path.exists('dist/MultiPlatformGUI/main.exe'): - exe_size = os.path.getsize('dist/MultiPlatformGUI/main.exe') / 1024 / 1024 - print(f"✅ 主程序验证通过: main.exe ({exe_size:.1f} MB)") - else: - print("⚠️ 重命名后主程序文件验证失败") - + os.rename(old_exe, new_exe) + print("✅ 主程序已重命名: MultiPlatformGUI.exe → main.exe") + + exe_size = os.path.getsize(new_exe) / 1024 / 1024 + print(f"✅ 主程序验证通过: main.exe ({exe_size:.1f} MB)") except Exception as e: - print(f"⚠️ 重命名失败: {e}") - print("💡 可以手动重命名: dist/main -> dist/MultiPlatformGUI") - print("📁 当前可用路径: dist/main/") + print(f"⚠️ 重命名主程序失败: {e}") + elif os.path.exists('dist/MultiPlatformGUI/main.exe'): + # 如果已经是 main.exe,直接验证 + exe_size = os.path.getsize('dist/MultiPlatformGUI/main.exe') / 1024 / 1024 + print(f"✅ 主程序验证通过: main.exe ({exe_size:.1f} MB)") else: - print("⚠️ 未找到 dist/main 目录,重命名跳过") + print("⚠️ 未找到主程序文件") # 创建使用说明 try: @@ -237,23 +236,23 @@ def verify_result(): """验证打包结果""" print("\n🔍 验证打包结果...") - # 优先检查MultiPlatformGUI(标准输出目录) + # 检查MultiPlatformGUI目录(统一输出目录) target_dir = "dist/MultiPlatformGUI" - fallback_dir = "dist/main" if os.path.exists(target_dir): return _verify_directory(target_dir) - elif os.path.exists(fallback_dir): - print(f"⚠️ 发现备用目录: {fallback_dir}") - print("💡 建议重命名为: dist/MultiPlatformGUI") - return _verify_directory(fallback_dir) else: - print("❌ 未找到任何打包输出目录") + print("❌ 未找到打包输出目录: dist/MultiPlatformGUI") + print("💡 请检查 PyInstaller 执行是否成功") return False def _verify_directory(base_dir): """验证指定目录的打包结果""" + # 检查可能的 exe 名称 exe_path = f"{base_dir}/main.exe" + if not os.path.exists(exe_path): + exe_path = f"{base_dir}/MultiPlatformGUI.exe" + internal_dir = f"{base_dir}/_internal" dll_path = f"{base_dir}/_internal/Utils/PythonNew32/SaiNiuApi.dll" static_dir = f"{base_dir}/_internal/static" @@ -339,15 +338,11 @@ def main(): print("\n" + "=" * 60) print("🎉 打包完成!") - # 智能显示可用路径 + # 显示打包结果 if os.path.exists("dist/MultiPlatformGUI"): print("📁 打包结果: dist/MultiPlatformGUI/") print("🚀 运行方式: cd dist/MultiPlatformGUI && .\\main.exe") print("📦 安装包构建: python installer/build_installer.py") - elif os.path.exists("dist/main"): - print("📁 打包结果: dist/main/") - print("🚀 运行方式: cd dist/main && .\\main.exe") - print("⚠️ 建议重命名: dist/main -> dist/MultiPlatformGUI") print("=" * 60)