Hi all,
I’m running JupyterHub 3.1.1 in a Docker container on Kubernetes. My virtual environment is located at:
/usr/src/myproject/.venv/
My goal is that when a user opens a terminal inside Jupyterhub, python
points to the venv, instead of the system Python (/usr/local/bin/python). Also, when executing shell commands in notebook cells using ! ...
, I want them to use the venv Python.
Currently, terminals show:
user@<pod>:~$ which python
/usr/local/bin/python
I’ve tried setting the spawner environment:
import os
venv_bin = "/usr/src/myproject/.venv/bin"
c.Spawner.environment = {
"PATH": f"{venv_bin}:{os.environ.get('PATH', '')}",
"VIRTUAL_ENV": "/usr/src/myproject/.venv"
}
This does not affect terminal shells or !
commands.
I’ve read about c.LocalProcessSpawner.shell_cmd
and profile scripts, but I’m not sure what the best practice is in JupyterHub 3.x to ensure all terminals and !
commands default to the virtual environment Python without hardcoding it in every user shell.
Any guidance or examples would be greatly appreciated.
Thanks!