Slicer kernel for jupyter notebook and python debugger setup in vscode


I have a few questions for getting a working setup of the jupyter notebook extension and Slicer working within VSCode. I’m still fairly new to making the switch from MATLAB to python, so some of these may be fairly obvious questions I am missing.

My main questions are:

  1. How to make sure I am pointing to the correct kernel to run a .ipynb file within vscode
  2. How to enable a debugger for jupyter lab in either vscode or within jupyter lab when running a slicer kernel

For the first question:
Currently on my Mac I recently installed Slicer 5.0.3 which I think overwrote Slicer 4.11. When running a jupyter notebook in jupyter lab with a slicer 5.0 kernel, the notebook works as expected. However, my Mac (and our lab’s PC I’ve set this up on) seems to think there are two available slicer kernels

When trying to run a jupyternotebook in vscode, it seems to only recognize the 4.11 kernel, and when I check the directory it is pointing the executable file it points to I believe should now be 5.0

For the second question:
From what I read, it seems that a debugger for a .ipynb (GitHub - SlicerRt/SlicerDebuggingTools: Extension for 3D Slicer containing various tools for module development and debugging ) is different than the python debugger (GitHub - SlicerRt/SlicerDebuggingTools: Extension for 3D Slicer containing various tools for module development and debugging )? Is this true and is it possible to setup debugging with a slicer kernel?

A minor question: when I launch vscode with the 4.11 kernel, it wants to launch 4 instances of slicer that shutdown quickly, and reduce to one running instance, but I’m wondering if there’s a way to get stop this behavior

I really appreciate the help! Please, let me know how to proceed or if there are posts I might have missed that address this.


Last time I tried VSCode had poor support for xeus kernels (slicer’s kernel is one of those). The workaround would be to use the VSCode remote jupyter kernel extension and launch the slicer-jupyter docker container. Then you should be able to connect to the kernel in the container from vscode

Hi Theadore,

Thank you this is very helpful to know! I will likely just stick with jupyterlab then instead of VS code since it seems to be a good working setup. At least until there is better support for xeus.

Do you have any suggestions for getting a debugger working in jupyter lab with a xeus kernel?

There is an issue with the debugger causing a deadlock when attached - see Add JupyterLab debugger support · Issue #69 · Slicer/SlicerJupyter · GitHub. It is a complex issue and there are alternative debuggers that you can use, so I’m not sure when it is going to be resolved.

1 Like

Great! Thanks for the help both!

1 Like

I have quick question. I tried following the steps outlined in but may be missing something.

Setting up the following json file for a remote attachment for the debugger.

I get the following connection error:

I also tried following some of the advice on this thread ( for setting up the correct python paths and autocomplete paths for vscode, but haven’t quite been able get autocompletion to work or recognize “import slicer” for example. From my understanding of this thread, it seems that getting a debugging connection alone will allow autocompletion?

Any help would be much appreciated! thanks!

To start debugging, you need to click “Connect” in Slicer before you can attach in VS Code. Follow exactly these steps.

What may be confusing is that the VS Code screenshot shows all 4 clicks that you need to make in VS Code. For initial setup you only need to click 1 and 2. Click 3 and 4 are for for starting debugging and they should be clicked after “Connect” button was clicked in Slicer.

1 Like