修改打包交脚本
This commit is contained in:
parent
22b17a1d5d
commit
8a103224b5
@ -26,16 +26,39 @@
|
|||||||
|
|
||||||
## 🚀 使用修复后的构建脚本
|
## 🚀 使用修复后的构建脚本
|
||||||
|
|
||||||
### 1. 测试环境
|
### 方法1: 简化构建(推荐)
|
||||||
```bash
|
```bash
|
||||||
python test_build.py
|
# Windows批处理
|
||||||
|
build_simple.bat
|
||||||
|
|
||||||
|
# 或直接运行Python脚本
|
||||||
|
python simple_windows_build.py
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. 运行构建
|
### 方法2: 完整构建
|
||||||
```bash
|
```bash
|
||||||
|
# 先测试环境
|
||||||
|
python test_build.py
|
||||||
|
|
||||||
|
# 运行完整构建
|
||||||
python windows_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命令行选项
|
### PyInstaller命令行选项
|
||||||
|
31
build_simple.bat
Normal file
31
build_simple.bat
Normal file
@ -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
|
196
simple_windows_build.py
Normal file
196
simple_windows_build.py
Normal file
@ -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()
|
@ -175,7 +175,7 @@ a = Analysis(
|
|||||||
'openpyxl.cell',
|
'openpyxl.cell',
|
||||||
'openpyxl.formatting',
|
'openpyxl.formatting',
|
||||||
|
|
||||||
# pandas相关
|
# pandas相关 - 完整导入
|
||||||
'pandas.io.excel',
|
'pandas.io.excel',
|
||||||
'pandas.io.common',
|
'pandas.io.common',
|
||||||
'pandas.io.parsers',
|
'pandas.io.parsers',
|
||||||
@ -191,17 +191,37 @@ a = Analysis(
|
|||||||
'pandas._libs.hashtable',
|
'pandas._libs.hashtable',
|
||||||
'pandas._libs.algos',
|
'pandas._libs.algos',
|
||||||
'pandas._libs.index',
|
'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',
|
||||||
'numpy.core.multiarray',
|
'numpy.core.multiarray',
|
||||||
'numpy.core.umath',
|
'numpy.core.umath',
|
||||||
'numpy.core._methods',
|
'numpy.core._methods',
|
||||||
'numpy.core._dtype_ctypes',
|
'numpy.core._dtype_ctypes',
|
||||||
'numpy.core._internal',
|
'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.format',
|
||||||
|
'numpy.lib.mixins',
|
||||||
|
'numpy.lib.scimath',
|
||||||
|
'numpy.lib.stride_tricks',
|
||||||
'numpy.random',
|
'numpy.random',
|
||||||
'numpy.random._pickle',
|
'numpy.random._pickle',
|
||||||
|
'numpy.random.mtrand',
|
||||||
|
'numpy.random._common',
|
||||||
|
'numpy.random._generator',
|
||||||
|
|
||||||
# 编码相关
|
# 编码相关
|
||||||
'encodings',
|
'encodings',
|
||||||
@ -217,10 +237,10 @@ a = Analysis(
|
|||||||
'pkg_resources.py2_warn',
|
'pkg_resources.py2_warn',
|
||||||
'pkg_resources.markers',
|
'pkg_resources.markers',
|
||||||
|
|
||||||
# Jinja2相关(可能被某些依赖使用)
|
# Jinja2相关(可选,某些依赖可能需要)
|
||||||
'jinja2',
|
# 'jinja2',
|
||||||
'jinja2.ext',
|
# 'jinja2.ext',
|
||||||
'markupsafe',
|
# 'markupsafe',
|
||||||
|
|
||||||
# Windows特定模块(仅在Windows上可用)
|
# Windows特定模块(仅在Windows上可用)
|
||||||
# 'win32api',
|
# 'win32api',
|
||||||
@ -324,18 +344,11 @@ exe = EXE(
|
|||||||
print("开始构建可执行文件")
|
print("开始构建可执行文件")
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|
||||||
|
# 使用spec文件时,只能使用基本选项
|
||||||
cmd = [
|
cmd = [
|
||||||
sys.executable, '-m', 'PyInstaller',
|
sys.executable, '-m', 'PyInstaller',
|
||||||
'--clean',
|
'--clean',
|
||||||
'--noconfirm',
|
'--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)
|
str(spec_file)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user