From ddbd79b9510768f824316671fc71670c5b2a9a4d Mon Sep 17 00:00:00 2001 From: renjue Date: Sat, 9 May 2026 16:43:11 +0800 Subject: [PATCH] Fix Docker startup install for externally managed Python environment. Install python3-venv and move backend dependency installation/runtime to a dedicated venv to avoid PEP 668 pip errors inside Debian-based container. Co-authored-by: Cursor --- Dockerfile | 2 +- docker/start.sh | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c53bf0c..3e66cc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN sed -i "s|deb.debian.org|${APT_MIRROR}|g; s|security.debian.org|${APT_MIRROR}|g" /etc/apt/sources.list.d/debian.sources RUN apt-get update \ - && apt-get install -y --no-install-recommends python3 python3-pip ca-certificates git \ + && apt-get install -y --no-install-recommends python3 python3-pip python3-venv ca-certificates git \ && rm -rf /var/lib/apt/lists/* WORKDIR /app diff --git a/docker/start.sh b/docker/start.sh index 1b5f502..86a5d2a 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -18,7 +18,11 @@ else fi echo "[start] installing backend dependencies" -python3 -m pip install --no-cache-dir -r "${WORKTREE_DIR}/backend/requirements.txt" +VENV_DIR="${WORKTREE_DIR}/.venv" +if [ ! -x "${VENV_DIR}/bin/python" ]; then + python3 -m venv "${VENV_DIR}" +fi +"${VENV_DIR}/bin/pip" install --no-cache-dir -r "${WORKTREE_DIR}/backend/requirements.txt" echo "[start] installing frontend dependencies and building" cd "${WORKTREE_DIR}/frontend" @@ -27,7 +31,7 @@ npm run build echo "[start] launching backend:${BACKEND_PORT} and frontend:${FRONTEND_PORT}" cd "${WORKTREE_DIR}/backend" -python3 app.py & +"${VENV_DIR}/bin/python" app.py & BACKEND_PID=$! cd "${WORKTREE_DIR}/frontend"