A comprehensive way to perform step by step debugging of Python code [closed]
Asked Answered
T

2

6

I was wondering is there is a good and comprehensive way to debug python code step by step so that I can have a better idea of all the variables involved, their dimensions and values?

What can be done to do step-by-step debugging?

Thereby answered 27/2, 2023 at 17:21 Comment(3)
If you use Jupyter Notebook from within VSCode then it works as normal but you can set breakpoints, see variable values, examine data structures and set watch expressions. See link, Really useful and simple to set up.Charliecharline
JupyterLab is the current generation of Jupyter interface and has a debugger mode that allows you to step through code. See this post here and related one here. Documentation is here. Look under 'Tutorial Notebook' section on that page for a link where you can try it out without installing anything on your own system.Lunkhead
@Lunkhead Sorry for such a late reply, came here after getting a notification, Jupyterlab was good enough for what I needed, please post it as an answer so i can accept and close the question. Thank youThereby
L
5

JupyterLab is the current generation of Jupyter interface and has a debugger mode that allows you to step through code. See this post here and a related one here.

Documentation is here.
You can try it out without installing anything on your own system by clicking here to launch a temporary Jupyter session running on a remote computer via the MyBinder service, and then open a new notebook file from the launcher. You can step the sections 'Debug code in notebook' and 'Explore the code state' there in the documentation.


For %%debug, which is from IPython that Jupyter inherits much from, see here and other posts in that thread.

Lunkhead answered 14/12, 2023 at 13:19 Comment(3)
what about using %debug ? any docs for this?Puissant
I added a link at the bottom.Lunkhead
Alright Wayne thanks!Puissant
S
1

vs code has a really good support of Jupyter notebooks. You can debug within the cell and go through cell contents line by line while looking at the variables in real-time. It also has a variable explorer that you can use to check your variables. You can also select the Python interpreter (from python venv or conda).

Just open any *.ipynb file in vs code and it will suggest you to install multiple extensions (e.g., Jupyter-related extensions) to work effectively with this. Even for the variable explorer, there are multiple extensions that can help you summarize your data on the go without any additional coding.

Signalize answered 8/7 at 20:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.