Skip to content

Jupyter Kernels and the Jupyter Extension

Rob Lourens edited this page Jan 24, 2023 · 8 revisions

Jupyter Kernels

The Jupyter Kernels category lists all Jupyter kernels that VS Code detects in the context of the compute system it’s operating in (your desktop, Codespaces, remote server, etc.). Each Jupyter kernel has a Jupyter kernel specification (or Jupyter kernelspec), which contains a JSON file (kernel.json) with details about the kernel—name, description, and CLI information required to launch a process as a kernel.

When the Visual Studio Code Jupyter extension is executing cells, it's using Jupyter kernels to execute the code and retrieve output to display in the notebook document. Users can install kernelspec files for different languages on their system. By installing them into the same locations as Jupyter they will get picked up by the Jupyter extension and should show up as options in the notebook kernel picker. These kernel will be shown in the kernel picker under the group label "Jupyter Kernel..."

Jupyter Kernels section of the kernel picker.

Python Environments

When the Python extension is installed, any Python environment (meaning a Python interpreter and an associated location for Python packages), installed on the system can be used as a kernel to execute Python code. Without the Python extension installed, the Jupyter extension can only find kernels installed into Jupyter-registered locations. The default kernel for Python is provided by the IPyKernel package. If you select an environment on the system that does not have IPyKernel installed and attempt to run the notebook, you will be prompted to install IPyKernel. If it's installed, that environment can be used as a valid kernel for Jupyter notebooks in Visual Studio Code.

Note: You do not need to install jupyter into the Python environment you want to use. Only IPython and IPyKernel are required to launch a Python process as a kernel and execute code against your notebook, e.g., pip install ipython ipykernel. Visit our wiki to learn more.

image

The Python extension can detect many different types of Python environments on a system and has an excellent guide to setting them up. In the kernel picker those interpreters will all be grouped up into different categories based on the interpreter type.

PythonKernels

Existing Jupyter Server

The Existing Jupyter Server category lists remote Jupyter servers previously connected. You can also use this option to connect to an existing Jupyter server running remotely or locally. Grab the URL for your Jupyter server, e.g., http://<ip-address>:<port>/?token=<token> and paste it in the Enter the URL of the running Jupyter server option to connect to the remote server and execute code against your notebook using that server.

Enter server URL

Note: When you’re starting the Jupyter server, ensure to: (1) allow all origins (e.g., --NotebookApp.allow_origin = '*') to allow your servers to be accessed externally, and (2) set the notebook to listen to listen on all IPs (e.g., --NotebookApp.ip = '0.0.0.0'). Once connected, all active Jupyter sessions will appear on this list. You can create new session from the server’s kernelspec by selecting the Notebook: Select Notebook Kernel command -> Select Another Kernel… -> Local Kernel Specs… -> your server. Member

Kernel Selection

When you pick a kernel in the kernel picker, that kernel will then be associated with that file and automatically selected the next time that you open it. If nothing has been selected, the Jupyter extension will take a look at the notebook metadata and attempt to select the best kernel for the file. That kernel will be label as the "suggested" kernel. For Python, if no environments look like an exact match the selected active environment of the Python extension in the given workspace will be used.

image

Note that when you have a kernel selected that only supports specific languages the code cells in the notebook document will be restricted to only the types supported by the current kernel.

image

Other Extensions providing kernels

There are other notebook extensions in the marketplace such as the Julia or the .NET Interactive that can also provide kernels. These kernels will show up in the kernel picker alongside those provided by the Jupyter extension.

image
Clone this wiki locally