正文
增加 14 行删除 14 行
47 行未改动48495051525354555657585910 行未改动70717273747576777879808182838485868788899091929394959697989910010110210326 行未改动13013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516625 行未改动47 行未改动import sysdef build_with_nuitka():"""使用Nuitka进行更优化的打包,生成更小的exe文件"""# 获取当前目录current_dir = os.path.dirname(os.path.abspath(__file__))# Nuitka命令参数 - 简化版本cmd = [sys.executable,'-m', 'nuitka',10 行未改动'--assume-yes-for-downloads', # 自动下载依赖# '--quiet', # 静默模式,减少输出'main.py']print("正在使用Nuitka进行优化打包...")print(f"命令: {' '.join(cmd)}")try:# 执行打包命令result = subprocess.run(cmd, cwd=current_dir, capture_output=True, text=True)if result.returncode == 0:print("✅ Nuitka打包成功!")print(f"生成的exe文件位置: {os.path.join(current_dir, 'dist_nuitka', 'main.exe')}")print("文件大小应该比PyInstaller打包的小30-50%")else:print("❌ Nuitka打包失败!")print("错误信息:")print(result.stderr)except FileNotFoundError:print("❌ 未找到Nuitka,请先安装:")print("pip install nuitka")except Exception as e:print(f"❌ 打包过程中出现错误: {e}")def build_with_cx_freeze():"""使用cx_Freeze进行打包"""# cx_Freeze setup脚本内容setup_content = '''import sysimport os26 行未改动options={"build_exe": build_exe_options},executables=[Executable("main.py", base=base)])'''# 写入setup脚本with open('setup_cxfreeze.py', 'w', encoding='utf-8') as f:f.write(setup_content)cmd = [sys.executable, 'setup_cxfreeze.py', 'build']print("正在使用cx_Freeze进行打包...")try:result = subprocess.run(cmd, cwd=current_dir, capture_output=True, text=True)if result.returncode == 0:print("✅ cx_Freeze打包成功!")print(f"生成的exe文件位置: {os.path.join(current_dir, 'dist_cxfreeze')}")else:print("❌ cx_Freeze打包失败!")print(result.stderr)except FileNotFoundError:print("❌ 未找到cx_Freeze,请先安装:")print("pip install cx_Freeze")if __name__ == "__main__":print("请选择打包方式:")print("1. Nuitka (推荐,文件更小)")print("2. cx_Freeze")choice = input("请输入选择 (1或2): ").strip()if choice == "1":build_with_nuitka()elif choice == "2":build_with_cx_freeze()25 行未改动47 行未改动48495051525354555657585910 行未改动70717273747576777879808182838485868788899091929394959697989910010110210326 行未改动13013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516625 行未改动47 行未改动import sysdef build_with_nuitka():"""使用Nuitka进行更优化的打包,生成更小的exe文件"""# 获取当前目录current_dir = os.path.dirname(os.path.abspath(__file__))# Nuitka命令参数 - 简化版本cmd = [sys.executable,'-m', 'nuitka',10 行未改动'--assume-yes-for-downloads', # 自动下载依赖# '--quiet', # 静默模式,减少输出'main.py']print("正在使用Nuitka进行优化打包...")print(f"命令: {' '.join(cmd)}")try:# 执行打包命令result = subprocess.run(cmd, cwd=current_dir, capture_output=True, text=True)if result.returncode == 0:print("✅ Nuitka打包成功!")print(f"生成的exe文件位置: {os.path.join(current_dir, 'dist_nuitka', 'main.exe')}")print("文件大小应该比PyInstaller打包的小30-50%")else:print("❌ Nuitka打包失败!")print("错误信息:")print(result.stderr)except FileNotFoundError:print("❌ 未找到Nuitka,请先安装:")print("pip install nuitka")except Exception as e:print(f"❌ 打包过程中出现错误: {e}")def build_with_cx_freeze():"""使用cx_Freeze进行打包"""# cx_Freeze setup脚本内容setup_content = '''import sysimport os26 行未改动options={"build_exe": build_exe_options},executables=[Executable("main.py", base=base)])'''# 写入setup脚本with open('setup_cxfreeze.py', 'w', encoding='utf-8') as f:f.write(setup_content)cmd = [sys.executable, 'setup_cxfreeze.py', 'build']print("正在使用cx_Freeze进行打包...")try:result = subprocess.run(cmd, cwd=current_dir, capture_output=True, text=True)if result.returncode == 0:print("✅ cx_Freeze打包成功!")print(f"生成的exe文件位置: {os.path.join(current_dir, 'dist_cxfreeze')}")else:print("❌ cx_Freeze打包失败!")print(result.stderr)except FileNotFoundError:print("❌ 未找到cx_Freeze,请先安装:")print("pip install cx_Freeze")if __name__ == "__main__":print("请选择打包方式:")print("1. Nuitka (推荐,文件更小)")print("2. cx_Freeze")choice = input("请输入选择 (1或2): ").strip()if choice == "1":build_with_nuitka()elif choice == "2":build_with_cx_freeze()25 行未改动