Run Quarto Python kernel inside the project venv, not base python
Build and Deploy Verso / deploy (push) Successful in 9m33s
Build and Deploy Verso / deploy (push) Successful in 9m33s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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; `
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user