Package: vip-ipykernel
ViP IPykernelVenv in Parent IPykernel - an IPython kernel for Jupyter that runs out the closest venvOverviewHow it WorksCaveats and GotchasVSCode Jupyter Notebook IntegrationVenv NamesAcknowledgementsTodoOverviewDo you usevenv's for all of your environments? Do you run Jupyter out of a
system/user installed location or via JupyterHub? Are you bored of making a
kernel for every single venv? Then this is the package for you!vip-ipykernel overwrites the defaultpython3kernel and replaces it with one
which will traverse directories upwards until it finds a.venvdirectory, if
it finds one then it will start the kernel with python out of that directory, if
it does not find a venv then it will carry on with the default python3.NOTE: Your venvmust have ipykernel installed in it, as this 'kernel' just
searches for and launches ipykernel out of the local venv. If ipykernel is not
available inside the venv then it will fail to start.This only needs to be installed once, you can do this withpip install vip-ipykernel --userto install it into your local user environment.Once the package is installed, runpython3 -m vip_ipykernel.kernelspec --userto install the kernel, now when you run a notebook with the defaultpython3kernel it will instead use the venv in a parent directory.If you want to revert the changes, runpython3 -m ipykernel install --user,
this will re-install the defaultpython3kernel.Alternatively, if you don't want to overwrite the default kernel, then you can
pass a name (python3 -m vip_ipykernel.kernelspec --user --name venv-kernel) to
so that the kernel appears separately in the list of kernels and the default
behaviour is not modified.How it WorksThe standard python3 kernel is:{
 "argv": [
  "/usr/bin/python3",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}This just says "Run usingpython3to runipykernel_launcherwith an argument-f {connection_file}". When you install the vip ipykernel this is replace by:{
 "argv": [
  "/usr/bin/python3",
  "-m",
  "vip_ipykernel_launcher",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}Which will instead run thevip_ipykernel.vip_ipykernel_launchermodule,
passing it the arguments-m ipykernel_launcher -f {connection_file}. The
module runs a functionvenv_searchwhich looks in the current directory, and
upwards to any parent directories, until it finds a.venvorvenvdirectory
containingbin/python3.If it finds a venv with python3 in it, it passes the arguments-m ipykernel_launcher -f {connection_file}to that python executable, which starts
and connects the kernel from that venv to your current session, in the same way
that a kernel installed for that specific venv would.If it does not find a venv, then it will default to the system python executable
and behave like the standardpython3kernel.Caveats and GotchasVSCode Jupyter Notebook IntegrationVSCode manages kernels for its notebooks with its own system, so it will not use
the vip-ipykernel.Venv NamesCurrently only venv's named.venvorvenvare searched for, if your venv has
a different name it won't be found, and if you have multiple venv's available
then the first one (sorted alphanumerically, so.venvtakes priority overvenv) will be used.AcknowledgementsThe kernel implementation and tests are largely copy-and-paste'd directly from
theipykernel projectwith some minor
modifications made to search for a venv and launch python out of it if possible.TodoExpand tests to different versions of ipykernel/jupyter_coreLook at ways to show kernel errorsSupport for other environments:Poetry-created venvs (poetry env info --path)Pipenv-created venvsPyenv-created venvsConda-created environmentsUser-configured venvsReading from vscode configuration?etc...