Last active
March 31, 2023 16:26
-
-
Save thvitt/9072336288921f57ec8741eb4b8b024e to your computer and use it in GitHub Desktop.
Register a jupyter kernel for the current pyenv.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ "$PYENV_VERSION" -ne "" ] | |
then | |
name=`pyenv version-name` | |
python=`pyenv which python` | |
else | |
name=`basename "$VIRTUAL_ENV"` | |
python="$VIRTUALENV/bin/python" | |
fi | |
jupyterdir=$(jupyter --data-dir) | |
kerneldir="${jupyterdir}/kernels/${name}" | |
echo "Installing jupyter kernel file $name for $python to $kerneldir ..." | |
pip install ipykernel | |
mkdir -p "$kerneldir" | |
cat > "$kerneldir"/kernel.json <<EOF | |
{ | |
"argv": [ "$python", "-m", "ipykernel", "-f", "{connection_file}" ], | |
"display_name": "$name", | |
"language": "python" | |
} | |
EOF | |
cat "$kerneldir"/kernel.json |
Hey, thanks for your gist! in case it's useful, I created a
pyenv
plugin to do this automatically when installing new versions/virtualenvs: https://github.com/aiguofer/pyenv-jupyter-kernel
@aiguofer I love your plugin! What a great community!
Thanks for this @thvitt! This script works, but when using it I ran into some trouble related to virtual environments and the __PYVENV_LAUNCER__
env var. I added a fork of this gist with a fix here: https://gist.github.com/telamonian/8f3a42cc98dbf08a8e1a8f7c4e8c2588
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, thanks for your gist! in case it's useful, I created a
pyenv
plugin to do this automatically when installing new versions/virtualenvs: https://github.com/aiguofer/pyenv-jupyter-kernel