Files
ai_wht_wechat/backend/rebuild_venv.bat
2026-01-06 19:36:42 +08:00

66 lines
1.7 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
chcp 65001 >nul
echo ========================================
echo 重建虚拟环境使用标准Python
echo ========================================
echo.
cd /d %~dp0
echo [步骤1] 删除旧的虚拟环境...
if exist venv (
rmdir /s /q venv
echo [完成] 旧虚拟环境已删除
) else (
echo [提示] 没有找到旧虚拟环境
)
echo.
echo [步骤2] 使用标准Python 3.12创建新虚拟环境...
py -3.12 -m venv venv
if %errorlevel% neq 0 (
echo [错误] 虚拟环境创建失败
pause
exit /b 1
)
echo [完成] 虚拟环境创建成功
echo.
echo [步骤3] 验证新虚拟环境的Python路径...
venv\Scripts\python.exe -c "import sys; print('Python可执行文件:', sys.executable); print('Python版本:', sys.version); print('\nsys.path前5行:'); [print(p) for i, p in enumerate(sys.path[:5])]"
echo.
echo [步骤4] 升级pip...
venv\Scripts\python.exe -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
echo.
echo [步骤5] 配置pip使用清华镜像...
venv\Scripts\pip.exe config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
echo [完成] pip镜像源已配置
echo.
echo [步骤6] 安装项目依赖...
venv\Scripts\pip.exe install -r requirements.txt
if %errorlevel% neq 0 (
echo [错误] 依赖安装失败
pause
exit /b 1
)
echo [完成] 依赖安装成功
echo.
echo [步骤7] 安装Playwright浏览器...
venv\Scripts\playwright.exe install chromium
if %errorlevel% neq 0 (
echo [警告] Playwright浏览器安装可能失败请手动检查
)
echo.
echo ========================================
echo 虚拟环境重建完成!
echo ========================================
echo.
echo 现在可以运行 start_service.bat 启动服务
echo.
pause