Skip to content

Instantly share code, notes, and snippets.

@markcheno
Forked from thvitt/register-jupyter-env
Created April 18, 2019 02:38
Show Gist options
  • Save markcheno/45981b31ffc1bba43832f814c0164f6b to your computer and use it in GitHub Desktop.
Save markcheno/45981b31ffc1bba43832f814c0164f6b to your computer and use it in GitHub Desktop.
Register a jupyter kernel for the current pyenv.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment