How to use debugger in JupyterLab

I have

jupyterlab              3.1.18
jupyterlab-pygments     0.1.2
jupyterlab-server       2.8.2
jupyterlab-widgets      1.0.0

To my understanding, debugger should be built-in when I am using Jupyter Lab now.
However, I couldn’t find any way to use it.
Can someone please explain how I can use debugger?
Thanks

The documentation should help here:

https://jupyterlab.readthedocs.io/en/stable/user/debugger.html

Please feel free to ask any questions if something is not clear.

@krassowski , Thanks, so I must create a dedicated conda env when I want to run with debugger?

No, absolutely not. The documentation includes an example of how to set up a fresh installation with conda, but there is no need for that. I don’t even have conda installed for my local JupyterLab uses (I use pyenv).

It would probably help if you could hint what are you struggling with. Do you see the bug icon? What kernel (and version of the kernel) are you using? Can you provide a screenshot. What version of JupyterLab displays if you go to Help → About JupyterLab (this can differ from the version you got from pip list if your paths are mis-configured).

@krassowski I am using Jupyter Lab 3.1.18 (in Help->About)
I already have a running notebook and I want to use debugger with its env, if possible.
I dont see a bug icon:
image
I am using Python3 as the Kernel. I started the session from the terminal tab within my PyCharm, from the venv of an existing project.

Thanks!

Let me clear up some terminology. Python 3 is a language. Kernel is a program wrapping or providing the language interpreter and adding extra functionality (which is characteristic of Jupyter notebooks) on top of it.

There are multiple kernels which provide support for Python 3. You likely use ipykernel; you may have been blissfully unaware of its existence because it did its job so well! However, this time is different; a new feature was added and you would like to make use of it. The documentation explains that:

For Python, both ipykernel (6.0+) and xeus-python support debugging.

Let me highlight that you need to have ipykernel in version 6 or newer to make use of the debugger. This is why I asked for the name and version of the kernel. After upgrading the bug icon should show up. Please let me know if it worked for you.

2 Likes

@krassowski Thanks, But given I open the jupyter lab from venv within my pyCharm - How can I ensure I use ipykernel and/or update it?

You can update ipykernel the same way as you update any other Python package. There are some useful instructions on linux - How do I update a Python package? - Stack Overflow and for your very specific use case: Install, uninstall, and upgrade Python packages | IntelliJ IDEA.

1 Like

The listing of versions that you provided in the first post seems to come from pip list (but I cannot ever be sure); if this the case you can confirm that you have ipykernel installed by checking pip list.

@krassowski Great, it worked after upgrading ipykernel from 5.5 to 6+ and now I can use debugger.
I have another question, I don’t see a way to add a new watch (the equivalent to this button of pyCharm).
image
is that possible ?

@krassowski The debugger doesnt seem to work properly for some reason, even for this simple cell:
image

It prints the value of b and won’t stop.
Any idea why?

You have modified the cell but not run it again (it is yellow/orange) - maybe you forgot to run it after setting the breakpoint?

works-for-me

@krassowski Thanks, I did run the cell again but after I restarted the kernel it worked.

  1. Is there a way to add a new watch in the debugger?
  2. Is there a way to use a view (e.g. scientific view) to easily watch complex object such as dataframes?

Thanks

1 Like
  1. Is there a way to add a new watch in the debugger?

like a breakpoint on watched expression? Sorry I did not get the question.

  1. Is there a way to use a view (e.g. scientific view) to easily watch complex object such as dataframes?

There will be in 4.0! https://github.com/jupyterlab/jupyterlab/pull/10299 was already merged and there is an ongoing work on Update variable renderer panels by fcollonval · Pull Request #11171 · jupyterlab/jupyterlab · GitHub.