stock-ai-agent/backend/diagnose.sh
2026-02-03 10:08:15 +08:00

101 lines
2.6 KiB
Bash
Executable File
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.

#!/bin/bash
# 诊断脚本 - 检查系统配置
echo "================================"
echo "系统诊断"
echo "================================"
echo ""
cd /Users/aaron/source_code/Stock_Agent/backend
# 1. 检查虚拟环境
echo "1. 检查虚拟环境..."
if [ -d "venv" ]; then
echo " ✓ 虚拟环境存在"
source venv/bin/activate
python_version=$(python --version 2>&1)
echo "$python_version"
else
echo " ❌ 虚拟环境不存在"
exit 1
fi
# 2. 检查.env文件
echo ""
echo "2. 检查配置文件..."
if [ -f "../.env" ]; then
echo " ✓ .env文件存在项目根目录"
elif [ -f ".env" ]; then
echo " ✓ .env文件存在backend目录"
else
echo " ❌ .env文件不存在"
exit 1
fi
# 3. 检查依赖包
echo ""
echo "3. 检查依赖包..."
packages=("fastapi" "uvicorn" "tushare" "pandas" "numpy" "sqlalchemy" "pydantic")
all_installed=true
for pkg in "${packages[@]}"; do
if python -c "import $pkg" 2>/dev/null; then
version=$(python -c "import $pkg; print($pkg.__version__)" 2>/dev/null || echo "unknown")
echo "$pkg ($version)"
else
echo "$pkg 未安装"
all_installed=false
fi
done
if [ "$all_installed" = false ]; then
echo ""
echo "请运行: pip install -r requirements.txt"
exit 1
fi
# 4. 测试配置加载
echo ""
echo "4. 测试配置加载..."
python -c "
from app.config import get_settings
settings = get_settings()
print(f' ✓ 配置加载成功')
print(f' - Tushare Token: {'已配置 (' + settings.tushare_token[:10] + '...)' if settings.tushare_token else '❌ 未配置'}')
print(f' - 智谱AI Key: {'已配置 (' + settings.zhipuai_api_key[:10] + '...)' if settings.zhipuai_api_key else '❌ 未配置'}')
" 2>&1
# 5. 测试模块导入
echo ""
echo "5. 测试模块导入..."
modules=("app.models.database" "app.services.cache_service" "app.services.tushare_service" "app.agent.core")
for module in "${modules[@]}"; do
if python -c "import $module" 2>/dev/null; then
echo "$module"
else
echo "$module 导入失败"
python -c "import $module" 2>&1 | head -5
fi
done
# 6. 检查端口占用
echo ""
echo "6. 检查端口占用..."
if lsof -i :8000 >/dev/null 2>&1; then
echo " ⚠ 端口8000已被占用"
lsof -i :8000
else
echo " ✓ 端口8000可用"
fi
echo ""
echo "================================"
echo "诊断完成"
echo "================================"
echo ""
echo "如果所有检查都通过,可以运行:"
echo " ./start.sh"
echo ""