Skip to content

fix: win_start.bat 兼容 .venv 并增加启动前置检查 - #116

Open
hailuohl wants to merge 2 commits into
jihe520:mainfrom
hailuohl:fix/win-start-bat-venv-detection
Open

fix: win_start.bat 兼容 .venv 并增加启动前置检查#116
hailuohl wants to merge 2 commits into
jihe520:mainfrom
hailuohl:fix/win-start-bat-venv-detection

Conversation

@hailuohl

@hailuohl hailuohl commented Sep 7, 2026

Copy link
Copy Markdown

Summary

win_start.bat 此前硬编码激活 .\backend\venv\,但 README「安装后端依赖」一节推荐的流程是 pip install uv; uv sync(生成的是 backend\.venv\)。照官方文档操作后,双击一键启动脚本直接失败(Activate.bat 路径不存在),README 第 315 行还明确承诺"windows用户直接双击运行 win_start.bat 即可启动项目"。

改动:

  • 虚拟环境探测:优先 backend\venv(保持现有用户路径不变),不存在则回退 backend\.venv(uv sync 产物);两者都没有时给出明确的中文指引(提示执行 cd backend + uv sync)后退出,不再无声闪退。
  • 启动前置检查:运行前用 where 检查 redis-serverpnpm 是否在 PATH,缺失时输出对应安装指引(Redis 的 Windows 下载地址 / npm install -g pnpm)并中止。
  • README 一致性(2 处小改):
    • PowerShell 创建虚拟环境处注明"若已执行 uv sync 可跳过,win_start.bat 会自动探测 venv / .venv";
    • step2 Windows 激活命令处注明 uv sync 用户的路径为 .\.venv\Scripts\Activate.ps1

技术说明

  • 逐段采用 goto 跳转而非括号块:实测发现 cmd 解析含中文的括号块时会把后续 echo 行拆断执行('Windows' is not recognized),改为 goto 结构后稳定。此问题已在 Windows 10 实机复现并验证修复。
  • venv 探测使用 if exist + if not defined 链式判断,无嵌套括号块。
  • 保持 UTF-8 无 BOM + CRLF + chcp 65001 原有约定不变。

验证

在 Windows 10 实机(Git Bash 环境构造测试副本、注释 start 行避免弹窗)覆盖 4 个场景:

场景 结果
无 redis-server(本机未装) 输出错误提示 + 下载地址行,干净退出(原版会继续启动三个窗口)
仅存在 backend\.venv(uv sync 用户) 正确探测 backend\.venv原版此场景直接失败
venv.venv 并存 优先 venv,与现有行为一致
两者皆无 输出修复指引后退出(原版为裸的"系统找不到指定的路径")

中文输出、URL 显示、错误退出码(exit /b 1)均验证正常。

@hailuohl hailuohl closed this Sep 7, 2026
@hailuohl
hailuohl force-pushed the fix/win-start-bat-venv-detection branch from c38b193 to 83d8783 Compare September 7, 2026 19:35
@hailuohl hailuohl reopened this Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant