"""安装项目依赖 - 最简方式"""
import subprocess
import sys
import os

pip = r"C:\Users\simon\.workbuddy\binaries\python\envs\default\Scripts\pip.exe"

# 逐步安装，避免一次性安装大包失败
packages_list = [
    # 核心依赖（有预编译 wheel）
    ["sqlalchemy>=2.0.0", "aiosqlite", "pytest", "pytest-asyncio"],
    # FastAPI 及其依赖
    ["fastapi", "uvicorn", "python-multipart"],
    # 其他
    ["httpx", "python-dotenv", "redis", "cryptography"],
]

results = []
for i, packages in enumerate(packages_list):
    result = subprocess.run(
        [pip, "install"] + packages,
        capture_output=True, text=True
    )
    results.append(f"--- Batch {i+1} (exit: {result.returncode}) ---")
    results.append(result.stdout[-500:] if result.stdout else "(no stdout)")
    if result.stderr:
        results.append(result.stderr[-300:])

output = "\n".join(results)
with open(r"C:\Users\simon\WorkBuddy\2026-05-21-16-57-26\install_batch.txt", "w", encoding="utf-8") as f:
    f.write(output)
