diff --git a/services/clsi/app/js/QuartoRunner.js b/services/clsi/app/js/QuartoRunner.js index 5a762656f0..4f2cc9cc57 100644 --- a/services/clsi/app/js/QuartoRunner.js +++ b/services/clsi/app/js/QuartoRunner.js @@ -168,15 +168,19 @@ function _pythonVenvPrep(venvBaseDir) { `if [ -n "$RHASH" ]; then ` + `VDIR="$VBASE/$RHASH"; mkdir -p "$VBASE" 2>/dev/null; ` + `( flock 9 || exit 0; ` + - `if [ ! -f "$VDIR/.verso-complete" ]; then ` + + `if [ ! -f "$VDIR/.verso-ready" ]; then ` + `echo "Installing Python packages from requirements.txt..."; rm -rf "$VDIR"; ` + `python3 -m venv --system-site-packages "$VDIR" ` + `&& "$VDIR/bin/pip" install --no-input --disable-pip-version-check -r requirements.txt ` + - `&& touch "$VDIR/.verso-complete" ` + + // Register a python3 kernelspec INSIDE the venv (argv -> the venv's python) + // so Quarto runs the kernel in the venv, not the base /usr/bin/python3 from + // the global kernelspec. ipykernel is visible via --system-site-packages. + `&& "$VDIR/bin/python3" -m ipykernel install --sys-prefix --name python3 --display-name "Python 3" ` + + `&& touch "$VDIR/.verso-ready" ` + `|| echo "ERROR: Failed to install Python packages from requirements.txt"; ` + `fi ` + `) 9>"$VBASE/.$RHASH.lock" 2>&1; ` + - `if [ -f "$VDIR/.verso-complete" ]; then export QUARTO_PYTHON="$VDIR/bin/python3"; fi; ` + + `if [ -f "$VDIR/.verso-ready" ]; then export QUARTO_PYTHON="$VDIR/bin/python3"; fi; ` + `fi; ` + `fi; ` )