# Is there a way to debug Jupyterlab .py code?

**URL:** <https://discourse.jupyter.org/t/is-there-a-way-to-debug-jupyterlab-py-code/1753>\
**Category:** JupyterLab\
**Created:** [July 24, 2019, 2:31am UTC](https://discourse.jupyter.org/t/is-there-a-way-to-debug-jupyterlab-py-code/1753 "2019-07-24T02:31:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan\_Yung](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/dylan_yung/32/951_2.png) [@Dylan\_Yung](https://discourse.jupyter.org/u/Dylan_Yung)\
**Post date:** [July 24, 2019, 2:31am UTC](https://discourse.jupyter.org/t/is-there-a-way-to-debug-jupyterlab-py-code/1753/1 "2019-07-24T02:31:25Z")

</div>

I can’t seem to a find a way to debug and step through the back-end code run by kernaes. Anyone have anyways stepping through and seeing what’s in the variables in the .py code while it’s being run by the kernel?

---

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [July 24, 2019, 4:31pm UTC](https://discourse.jupyter.org/t/is-there-a-way-to-debug-jupyterlab-py-code/1753/2 "2019-07-24T16:31:53Z")

</div>

Hi Dylan,

Assuming you are looking to debug a Python script ending in `.py` that you are triggering to run via `%run` in a JupyterLab cell:

My favorite legit way instead of just putting `print()` in the script is to just put `from IPython import embed; embed()` into the code at a point you want to trigger dropping into an interactive prompt where you can query variables. The prompt you drop into is IPython based so if you set a variable `my_var` earlier you can just type `my_var` to see its state. No need for `print(my_var)`.

(Aside: Using `print()` as a debugging step will be easier soon with Python 3.8 that adds the `=` specifier to the f-string syntax, see [here](https://stribny.name/blog/2019/06/debugging-python-programs).)

JupyterLab also has the terminal available so you could just use that and your standard debugging routes too. For example, you can use the terminal to launch IPython and then run some `.py` code with `%run` and then when an error is encountered, type `%debug` to do a post-mortem analysis. There are a lot more possibilities via the terminal but I won’t go into them since they are the more traditional route and you are more likely to find plenty of examples with a little searching on the internet. ([pysnooper](https://github.com/cool-RR/pysnooper) looks interesting and actively being developed.)

If you are talking about just running Python code in a JupyterLab cell and debugging that, then you have even more possibilities. See [here](https://davidhamann.de/2017/04/22/debugging-jupyter-notebooks/) or [here](https://www.blog.pythonlibrary.org/2018/10/17/jupyter-notebook-debugging/). I haven’t tried it yet but there is even [this fancy visual debugger](https://medium.com/ibm-watson-data-lab/the-visual-python-debugger-for-jupyter-notebooks-youve-always-wanted-761713babc62), although it looks like it only works in the classic notebook interface and not JupyterLab.  
In the future debugging code directly in the notebook could be a lot more interactive with an in-development debugger extension for JupyterLab, see the demo animation in [this tweet by @jtp](https://twitter.com/jtpio/status/1154416962954498048).

---

<div class="post-metadata">

**Author:** ![Dylan\_Yung](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/dylan_yung/32/951_2.png) [@Dylan\_Yung](https://discourse.jupyter.org/u/Dylan_Yung)\
**Post date:** [July 26, 2019, 9:06pm UTC](https://discourse.jupyter.org/t/is-there-a-way-to-debug-jupyterlab-py-code/1753/3 "2019-07-26T21:06:28Z")

</div>

Perfect thanks so much! Do you have an suggestions for debugging the front-end aspect? I’m using Jupyter Lab for a research project at university of british columbia and we’re having an issue debugging through the front-end. They decided to do TS with a Vue components in the frontend, but because of how jupyter lab interface is setup Vue debugger for chrome does not detect Vue components in the browser. Any suggestions?

---

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [July 28, 2019, 3:47pm UTC](https://discourse.jupyter.org/t/is-there-a-way-to-debug-jupyterlab-py-code/1753/4 "2019-07-28T15:47:02Z")

</div>

I cannot offer anything for that.  
Given the title of this thread, I’d suggest starting a new post for that question. That will give it better visibility.

---

<div class="post-metadata">

**Author:** ![bennetcole](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@bennetcole](https://discourse.jupyter.org/u/bennetcole)\
**Post date:** [October 24, 2019, 2:13pm UTC](https://discourse.jupyter.org/t/is-there-a-way-to-debug-jupyterlab-py-code/1753/5 "2019-10-24T14:13:13Z")

</div>

Python has a [debugger](http://net-informations.com/python/iq/debug.htm) , which is available as a module called pdb . It supports setting conditional breakpoints , stepping through the source code one line at a time, stack inspection, and more.

```
import pdb
msg = "this is a test"
pdb.set_trace()
print(msg)

```

Insert pdb.set\_trace() anywhere and it will function as a breakpoint . When you execute the script by python test.py, you will in the debug mode.

---

<div class="post-metadata">

**Author:** ![martinRenou](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/martinrenou/32/1655_2.png) [@martinRenou](https://discourse.jupyter.org/u/martinRenou)\
**Post date:** [March 27, 2020, 8:37am UTC](https://discourse.jupyter.org/t/is-there-a-way-to-debug-jupyterlab-py-code/1753/6 "2020-03-27T08:37:41Z")

</div>

A new JupyterLab debugger extension has been released [https://blog.jupyter.org/a-visual-debugger-for-jupyter-914e61716559](https://blog.jupyter.org/a-visual-debugger-for-jupyter-914e61716559). You might want to check it out 😉

---

<div class="post-metadata">

**Author:** ![telamonian](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/telamonian/32/2432_2.png) [@telamonian](https://discourse.jupyter.org/u/telamonian)\
**Post date:** [November 18, 2020, 1:00pm UTC](https://discourse.jupyter.org/t/is-there-a-way-to-debug-jupyterlab-py-code/1753/7 "2020-11-18T13:00:50Z")

</div>

You can do simultaneous debugging of the Typescript and Python code of a Jupyterlab extension using vscode. WIth breakpoints and everything!

It does require some config files to set this up. Said config can be supplied by the cookiecutter at [https://github.com/jupyterlab/debug-config-cookiecutter](https://github.com/jupyterlab/debug-config-cookiecutter)
