fix: build_linux.sh 添加 venv 降级机制,适配无 python3-venv 环境

This commit is contained in:
root
2026-04-29 11:00:37 +08:00
parent 159d22510b
commit 2d2c87d505

View File

@ -12,12 +12,27 @@ if ! command -v python3 &> /dev/null; then
echo "Error: python3 not found"; exit 1
fi
VENV_DIR="$PROJECT_ROOT/.venv_build"
echo "Creating virtual environment: $VENV_DIR"
python3 -m venv "$VENV_DIR"
source "$VENV_DIR/bin/activate"
pip install --upgrade pip
pip install -r requirements.txt
# ── 尝试 venv 隔离构建,失败则用系统环境 ──
USE_VENV=false
if python3 -m venv --help &>/dev/null; then
VENV_DIR="$PROJECT_ROOT/.venv_build"
if python3 -m venv "$VENV_DIR" 2>/dev/null; then
source "$VENV_DIR/bin/activate"
USE_VENV=true
echo "Using virtual environment"
pip install --upgrade pip -q
pip install -r requirements.txt -q
else
echo "Warning: venv creation failed, falling back to system Python"
fi
else
echo "Warning: python3-venv not available, falling back to system Python"
fi
if [ "$USE_VENV" = false ]; then
pip install -r requirements.txt --break-system-packages -q 2>/dev/null || \
pip install -r requirements.txt -q 2>/dev/null || true
fi
echo "Cleaning previous builds..."
rm -rf dist/ build/trulymem/ 2>/dev/null || true
@ -25,13 +40,15 @@ rm -rf dist/ build/trulymem/ 2>/dev/null || true
echo "================================"
echo "Building TrulyMEM (TUI + Web embedded)"
echo "================================"
python -m PyInstaller --clean build/trulymem.spec --noconfirm
python3 -m PyInstaller --clean build/trulymem.spec --noconfirm
echo "================================"
echo "===== Build Complete ====="
echo "Binary: dist/TrulyMEM"
ls -la dist/
deactivate
rm -rf "$VENV_DIR"
if [ "$USE_VENV" = true ]; then
deactivate 2>/dev/null || true
rm -rf "$VENV_DIR"
fi
echo "Build finished successfully!"