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?

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. Commented Feb 27, 2023 at 17:27
  • 1
    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. Commented Feb 27, 2023 at 18:49
  • @Wayne 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 you Commented Dec 14, 2023 at 12:19

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

what about using %debug ? any docs for this?
I added a link at the bottom.
Alright Wayne thanks!
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.