mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Jupyter Kernel Code Execution Sample
This is a very simple extension sample demonstrating the use of the Jupyter Extension API allowing other extensions to execute code against Jupyter Kernels.
- The sample lists finds kernels associated with notebooks that are currently open in the workspace.
- The sample the filters the kernels by language, focusing on Python kernels.
- Upon selecting a Python kernel, code selected by the user is executed against the selected kernel
- The output is displayed in an output panel.
- The sample demonstrates the ability to retrieve outputs of various mime types, including streamed output.
Running this sample
cd jupyter-kernel-execution-samplecode .: Open the folder in VS Code- Run
npm installin terminal to install the dependencies - Run the
Run Extensiontarget in the Debug View. This will:- Start a task
npm: watchto compile the code - Run the extension in a new VS Code window
- Start a task
- Open a Jupyter Notebook and select a Python kernel and execute some code.
- Select the command
Jupyter Kernel API: Execute code against a Python Kernel - Select the a Kernel and then select the Code to execute.
- Watch the output panel for outputs returned by the kernel.
Notes:
- Make use of the
languageproperty of the kernel to ensure the language of the code matches the kernel. getKernelAPI can can returnundefinedif the user does not grant the extension access to the kernel.- Access to kernels for each extension is managed via the command
Manage Access To Jupyter Kernels.