Terminals and ! commands in JupyterHub not using virtualenv Python

Can you check if your c.Spawner.environment config is having any effect? e.g. setting “TESTVARIABLE”: “TESTVALUE”? It could be that the config isn’t being loaded, or is being overridden by some later config. Check the value of $VIRTUAL_ENV and $PATH.

For the most part, I would expect your config to work, so I expect something is getting a little wonky

If you want a virtualenv to be truly fully activated, including whatever setup scripts, you’re right that c.LocalProcessSpawner.shell_cmd could be part of it. For such things, I usually use the c.Spawner.cmd approach, where you write a shell script that does activation, etc. (maybe even bash -l), then always ends with exec jupyterhub-singleuser "$@":

#!/bin/bash -l
# ^login shell means source everything in profile.d, bash_profile, etc.

# activate the project env
source /usr/src/myproject/.venv/bin/activate

# finally, 'become' jupyterhub-singleuser
exec jupyterhub-singleuser "$@"
2 Likes