Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataScience - Using ipdb.set_trace() in python interactive mode #533

Closed
jacquespeeters opened this issue Oct 6, 2020 · 8 comments
Closed
Assignees

Comments

@jacquespeeters
Copy link

VScode is getting more popular into DataScience community because of its REPL (interactive python window) while being a better than IDE than Jupyter Notebooks.

Usually people (or atleast me in Pycharm) debug with import ipdb; ipdb.set_trace() or import pdb; pdb.set_trace(). input/output and then redirected to the console (same behaviour on Rstudio). However in VScode input is redirected to a new small top window which block any action (see screenshot).

image

Debugging in VScode while using interactive python is currently not possible and it is painful. Am I missing something (eventhough i spent time on google before making this issue) or is the feature not supported? What is the best way to debug in Python interactive mode?

@rchiodo
Copy link
Contributor

rchiodo commented Oct 7, 2020

Debugging using the interactive window doesn't require you use ipdb at all. It's built into running and executing cells. Please see the docs here:
https://code.visualstudio.com/docs/python/jupyter-support-py#_debug-a-jupyter-notebook

@rchiodo rchiodo closed this as completed Oct 7, 2020
@rchiodo
Copy link
Contributor

rchiodo commented Oct 7, 2020

Specifically if you open a python file and add the #%% marker on a line, you can click the 'debug cell' code lens:

image

@rchiodo
Copy link
Contributor

rchiodo commented Oct 7, 2020

There's also an experimental way to debug inside of a jupyter notebook:
https://devblogs.microsoft.com/python/python-in-visual-studio-code-june-2020-release/#run-by-line

@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 11, 2020
@m-beau
Copy link

m-beau commented Mar 12, 2021

Hi, I do not succeed to use your built-in debugger within a jupyter notebook (NOT an interactive ipython session ran from a python script). Setting a breakpoint() inside a cell doesn't work.

All I wish is to be able to use the python debugger with the magic command %pdb, as it is possible when running a jupyter notebook with jupyter. Currently, adding %pdb on at the beginning of a cell makes it run indefinitely - as if a user input were expected (but it cannot be provided since no input box appears in your interface).

@rchiodo
Copy link
Contributor

rchiodo commented Mar 12, 2021

All I wish is to be able to use the python debugger with the magic command %pdb, as it is possible when running a jupyter notebook with jupyter. Currently, adding %pdb on at the beginning of a cell makes it run indefinitely - as if a user input were expected (but it cannot be provided since no input box appears in your interface).

Sorry %pdb is not supported. The only options at the moment are the Run By line experiment (which only works in the stable version of VS code when not using the new UI) and debugging through the interactive window.

Debugging of notebooks in general is on our backlog. For more information, you can track this issue here:
#1652

@m-beau
Copy link

m-beau commented Mar 12, 2021

Thank you for your reply. Nice to see that you are planning to implement it.

Related question: in spyder, when %pdb is ON and that an unhandled error is raised, the python console enters in python debug mode and the editor jumps to the file where the error occurs, very conveniently pointing the relevant line with a blue arrow. Is there any similar workflow in VScode? I am thinking about transitioning, and I am 90% convinced but the inability to debug my code makes it a strong no-go at the moment.

@rchiodo
Copy link
Contributor

rchiodo commented Mar 12, 2021

Is there any similar workflow in VScode?

There will be when we implement notebook debugging. Right now regular python debugging (or interactive window debugging) work this way. Unhandled exceptions stop where the exception is thrown.

@m-beau
Copy link

m-beau commented Mar 12, 2021

Cheers, I am describing my feature request in a more concise way at #1652.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants