Initial commit of WQ_GUI

This commit is contained in:
2026-04-08 15:25:08 +08:00
commit 91e36407ae
302 changed files with 40872 additions and 0 deletions

44
scripts/build.bat Normal file
View File

@ -0,0 +1,44 @@
@echo off
chcp 65001 >nul
echo.
echo ================================================
echo 水质参数反演分析系统 - 打包工具
echo ================================================
echo.
:: 检查是否在正确目录
if not exist "src\gui\water_quality_gui.py" (
echo [错误] 请在项目根目录下运行此脚本!
pause
exit /b 1
)
echo [1/4] 清理旧构建文件...
if exist "build" rmdir /s /q build
if exist "dist" rmdir /s /q dist
echo [2/4] 确保依赖已安装...
python -m pip install -r requirements.txt --quiet
python -m pip install pyinstaller --quiet
echo [3/4] 开始打包(首次可能需要 5-15 分钟,请耐心等待)...
pyinstaller --clean scripts/water_quality_gui.spec
echo.
echo [打包提示] 如果仍然出现 "No module named 'styles'",请检查:
echo 1. dist\water_quality_gui\styles.py 是否存在
echo 2. 是否需要添加 --collect-all styles 参数
echo.
echo [4/4] 打包完成!
echo.
echo 输出位置:
echo dist\water_quality_gui\water_quality_gui.exe
echo dist\water_quality_gui\_internal\
echo.
echo 建议:
echo 1. 将 dist 文件夹整个复制给用户(包含所有依赖)
echo 2. 首次运行可能需要 10-30 秒解压(正常现象)
echo 3. 如遇 DLL 缺失,可尝试在 conda 环境中打包
echo.
pause

View File

@ -0,0 +1,25 @@
import os
import sys
def _safe_add(path: str) -> None:
if not path or not os.path.isdir(path):
return
try:
if hasattr(os, "add_dll_directory"):
os.add_dll_directory(path)
except Exception:
pass
try:
os.environ["PATH"] = path + os.pathsep + os.environ.get("PATH", "")
except Exception:
pass
# PyInstaller onefile 解包目录
base = getattr(sys, "_MEIPASS", None)
if base:
_safe_add(base)
_safe_add(os.path.join(base, "lib-dynload"))
_safe_add(os.path.join(base, "DLLs"))