环境 ok

This commit is contained in:
yml2213
2026-09-11 22:05:11 +08:00
parent c5f14bdfd6
commit 424d547417
6 changed files with 231 additions and 12 deletions
+20 -8
View File
@@ -47,9 +47,13 @@ check_python_module() {
local module=$1
local import_name=${2:-$1}
local name=${3:-$1}
local py_bin="python3"
if [ -f ".venv/bin/python" ]; then
py_bin=".venv/bin/python"
fi
if python3 -c "import $import_name" 2>/dev/null; then
local version=$(python3 -c "import $import_name; print(getattr($import_name, '__version__', 'installed'))" 2>/dev/null || echo "installed")
if $py_bin -c "import $import_name" 2>/dev/null; then
local version=$($py_bin -c "import $import_name; print(getattr($import_name, '__version__', 'installed'))" 2>/dev/null || echo "installed")
echo -e " ${GREEN}✓${NC} $name: $version"
return 0
else
@@ -65,9 +69,16 @@ check_command "node" "Node.js" "https://nodejs.org/ 或 brew install node" || ((
check_command "npm" "npm" "随 Node.js 一起安装" || ((errors++))
echo ""
echo "▸ Python 环境"
check_command "python3" "Python 3" "https://python.org/ 或 brew install python3"
check_command "pip3" "pip3" "随 Python 3 一起安装"
echo "▸ Python 与虚拟环境 (uv 强约束)"
check_command "uv" "uv 包管理器" "curl -LsSf https://astral.sh/uv/install.sh | sh 或 brew install uv" || ((errors++))
if [ -d ".venv" ] && [ -f ".venv/bin/python" ]; then
venv_py_version=$(.venv/bin/python --version 2>&1)
echo -e " ${GREEN}✓${NC} .venv 虚拟环境: 已就绪 ($venv_py_version)"
else
echo -e " ${YELLOW}○${NC} .venv 虚拟环境: 未创建(运行 uv venv 创建)"
((errors++))
fi
echo ""
echo "▸ 浏览器"
@@ -89,7 +100,7 @@ check_node_module "node-forge" "node-forge"
check_node_module "jsdom" "jsdom"
echo ""
echo "▸ Python 包"
echo "▸ .venv Python 包 (uv 管理)"
check_python_module "requests" "requests" "requests"
check_python_module "pycryptodome" "Crypto" "pycryptodome"
check_python_module "execjs" "execjs" "PyExecJS"
@@ -106,11 +117,12 @@ echo "=========================================="
if [ $errors -gt 0 ]; then
echo -e " ${RED}检查完成: $errors 个必需依赖缺失${NC}"
echo ""
echo " 快速安装缺失依赖:"
echo " 快速修复与安装:"
echo " Node.js: npm install -g crypto-js axios node-forge"
echo " Python: pip3 install requests pycryptodome execjs"
echo " Python: uv venv && uv pip install requests pycryptodome execjs"
exit 1
else
echo -e " ${GREEN}检查完成: 环境就绪${NC}"
exit 0
fi