Merge pull request #298 from njiangk/fix/python-3-10-startup-check

fix: require Python 3.10+ in edict startup scripts
This commit is contained in:
cft0808
2026-04-27 22:30:20 +08:00
committed by GitHub
4 changed files with 27 additions and 8 deletions

1
.gitignore vendored
View File

@@ -30,6 +30,7 @@ venv/
# Node.js
node_modules/
edict/frontend/node_modules/
edict/frontend/dist/
*.tsbuildinfo
# Vite cache

View File

@@ -284,7 +284,7 @@ docker compose up
#### 前置条件
- [OpenClaw](https://openclaw.ai) 已安装
- Python 3.9+
- Python 3.10+
- macOS / Linux
#### 安装

View File

@@ -8,6 +8,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export EDICT_HOME="${EDICT_HOME:-$(dirname "$SCRIPT_DIR")}"
PYTHON_BIN="${EDICT_PYTHON:-python3}"
INTERVAL="${1:-15}"
LOG="/tmp/sansheng_liubu_refresh.log"
PIDFILE="/tmp/sansheng_liubu_refresh.pid"
@@ -58,14 +59,14 @@ echo " 按 Ctrl+C 停止"
safe_run() {
local script="$1"
if command -v timeout &>/dev/null; then
timeout "$SCRIPT_TIMEOUT" python3 "$script" >> "$LOG" 2>&1 || {
timeout "$SCRIPT_TIMEOUT" "$PYTHON_BIN" "$script" >> "$LOG" 2>&1 || {
local rc=$?
if [[ $rc -eq 124 ]]; then
echo "$(date '+%H:%M:%S') [loop] ⚠️ 脚本超时(${SCRIPT_TIMEOUT}s): $script" >> "$LOG"
fi
}
else
python3 "$script" >> "$LOG" 2>&1 || true
"$PYTHON_BIN" "$script" >> "$LOG" 2>&1 || true
fi
}

View File

@@ -9,11 +9,27 @@ cd "$REPO_DIR"
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
# 检查 Python
if ! command -v python3 &>/dev/null; then
echo -e "${RED}❌ 未找到 python3请先安装 Python 3.9+${NC}"
resolve_python() {
local candidate version major minor
for candidate in "${EDICT_PYTHON:-}" python3.12 python3.11 python3.10 python3; do
[ -n "$candidate" ] || continue
command -v "$candidate" &>/dev/null || continue
version=$("$candidate" -c 'import sys; print(f"{sys.version_info[0]}.{sys.version_info[1]}")' 2>/dev/null) || continue
major=${version%%.*}
minor=${version#*.}
if [ "$major" -gt 3 ] || { [ "$major" -eq 3 ] && [ "$minor" -ge 10 ]; }; then
echo "$candidate"
return 0
fi
done
return 1
}
PYTHON_BIN=$(resolve_python) || {
echo -e "${RED}❌ 未找到可用的 Python 3.10+(当前项目实际需要 3.10+${NC}"
exit 1
fi
}
export EDICT_PYTHON="$PYTHON_BIN"
# 确保 data 目录存在
mkdir -p "$REPO_DIR/data"
@@ -57,7 +73,8 @@ fi
# 启动看板服务器
echo -e "${GREEN}▶ 启动看板服务器...${NC}"
python3 dashboard/server.py &
echo -e "${GREEN} 使用 Python: ${PYTHON_BIN} ($($PYTHON_BIN --version 2>&1))${NC}"
"$PYTHON_BIN" dashboard/server.py &
SERVER_PID=$!
sleep 1