From 8530c5ebe0c9ff88a1e4410849351ea8b8799c5e Mon Sep 17 00:00:00 2001 From: claude Date: Tue, 2 Jun 2026 13:50:01 +0000 Subject: [PATCH] Run Quarto Python kernel inside the project venv, not base python MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The global python3 kernelspec hardcodes /usr/bin/python3, so even with QUARTO_PYTHON pointing at the project venv, Quarto launched the kernel in the base interpreter — packages installed into the venv (e.g. openpyxl) were not importable. Register a python3 kernelspec inside the venv via 'ipykernel install --sys-prefix' (kernel.json argv -> the venv's python); since Quarto runs kernel discovery through QUARTO_PYTHON, the venv's kernelspec is found ahead of the global one and the kernel runs in the venv. Bump the completion marker (.verso-complete -> .verso-ready) so venvs built before this change are rebuilt with the kernelspec. Co-Authored-By: Claude Opus 4.8 --- services/clsi/app/js/QuartoRunner.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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; ` )