vscode-jupyter icon indicating copy to clipboard operation
vscode-jupyter copied to clipboard

Enable Python Interactive for use as a debugging console

Open geophpherie opened this issue 6 years ago • 73 comments

I think this is related to / mentioned deep in the comments here, but I'm not convinced they're quite duplicates.

I think it'd be tremendously useful to be able to also select Python Interactive as your debug terminal, essentially launching a Python Interactive window at a breakpoint with the state of your program loaded into it, giving you access to your variables. That way plotting functions and visualizations could be made use of pretty easily as a way of debugging. This varies slightly from the current "Debug Current File in Python Interactive window", which would run your entire script in Python Interactive, in that you are still able to configure the debugger launch.json. For my specific use case it would allow passing in command line args to the script, while still being able to debug in Python Interactive.

At a high level, I can see two ways of it happening:

  1. Use only Python Interactive and allow it to continue execution of the code as the full debug tool.
  2. Use the main debug terminal for the debugging flow, but at a breakpoint launch the Python Interactive window that opens preloaded with the current program state. At that point, the Python Interactive window is essentially detached from debugger, but at least has the data from the program at that time, allowing for more native exploring of the variables. Once the user continues debugging, the current Python Interactive window is either updated or a new one is launched at the next breakpoint.

My current work around is just to write a data frame to a .csv in the current debugger, then load it into Python Interactive - which works well enough, but I think it'd be really helpful if they were somehow integrated!

Thank you for making this product so awesome to use!

geophpherie avatar Aug 14 '19 19:08 geophpherie

@jbeyer16. I like this suggestion, right now there is a bit of an odd bifurcation between the debugging and interactive debugging workflows. We'll consider it in the next triage meeting.

IanMatthewHuff avatar Aug 16 '19 17:08 IanMatthewHuff

awesome! looking forward to seeing how it develops. thanks!

geophpherie avatar Aug 16 '19 22:08 geophpherie

Great suggestion @jbeyer16. Thanks for considering @IanMatthewHuff - the described functionality would be a huge improvement for my workflow.

alexhamiltonRN avatar Aug 18 '19 14:08 alexhamiltonRN

@gramster I understand debugging Python inside Jupyter is not easy. Did you check out how the problem was solved in 2018 by PixieDebugger? (https://medium.com/codait/the-visual-python-debugger-for-jupyter-notebooks-youve-always-wanted-761713babc62)

adamryczkowski avatar Nov 03 '19 12:11 adamryczkowski

We’re not trying to implement a debugger that runs entirely in Jupyter cells; for us we have to integrate the debugger into the overall Visual Studio Code debug experience. It’s a different problem.

On Sun, Nov 3, 2019 at 4:57 AM Adam Ryczkowski [email protected] wrote:

@gramster https://github.com/gramster I understand debugging Python inside Jupyter is not easy. Did you check out how the problem was solved in 2018 by PixieDebugger? ( https://medium.com/codait/the-visual-python-debugger-for-jupyter-notebooks-youve-always-wanted-761713babc62 )

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode-python/issues/6972?email_source=notifications&email_token=AAVCPCBGAOJT4LOQQ5PZ6XLQR3DCHA5CNFSM4ILYADY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC5R6QQ#issuecomment-549134146, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVCPCFNKSK6XSNSHGB7HULQR3DCHANCNFSM4ILYADYQ .

gramster avatar Nov 03 '19 15:11 gramster

Yes this would be a great feature, just like in Spyder the debug console is limited and not easy to use. Interactive python is much better

mwindowshz avatar Nov 12 '19 08:11 mwindowshz

This is actually extremely useful for data-science oriented work. PyCharm somehow does this seamlessly, when debugging a regular Python project, the "Debug console" is actually an IPython one. That means, for instance, that it can be used for interactive matplotlib plotting even when the project is not executed in jupyter.

I'm interested to understand how something like this would be implemented to see if I can find some "ugly" temporary workaround. So maybe I can start some sort of listener server in my own code , then when stopped on a breakpoint I coudl launch IPython from the terminal and somehow "attach" it to my current session

syagev avatar Nov 13 '19 22:11 syagev

@syagev don't know if this is what you want but it's kind of workaround and it's definitely ugly :) you can launch an embedded IPython REPL right from the DEBUG CONSOLE tab

    import IPython
    IPython.embed()

and interact with it at the TERMINAL tab.

netanelrabinowitz avatar Dec 24 '19 10:12 netanelrabinowitz

Has there been any update on this ? I love VScode but this is the sole reason I don't use it over my current IDE

derekeden avatar Jan 27 '20 19:01 derekeden

I need this feature man.

sushant-tj avatar Jan 30 '20 13:01 sushant-tj

I need this feature man.

same - honestly would love to use VSCode as my main IDE but there's no way I can effectively debug without an interactive debugger

derekeden avatar Jan 30 '20 16:01 derekeden

I didn't know this wasn't possible and just lost my morning trying different configuration options to make it so. This feature is a must have for me. I find the inconsistency between debug and interactive consoles annoying

robfromdublin avatar Feb 17 '20 03:02 robfromdublin

Awesome! I am looking forward to a new interactive debug like WingIDE's. Thanks

fengyanghe avatar Feb 25 '20 10:02 fengyanghe

@NetanelRabinowitz This is such a useful hint. It would be great if this could be made into an automatic process somehow so that everything a particular debug config was run the terminal would have an interactive IPython session.

bashtage avatar Apr 24 '20 10:04 bashtage

I think the original problem could possibly have been solved by allowing the user to specify the interactive debug settings in the launch.json.

rchiodo avatar Apr 29 '20 16:04 rchiodo

This is absolutely an necessary feature for data science and machine learning projects. can we have it?

sedghi avatar Apr 29 '20 19:04 sedghi

Which 'this' are you referring to? Launch with interactive as an option in the launch.json is likely possible, but connect to a python process with the interactive console is not.

rchiodo avatar Apr 29 '20 19:04 rchiodo

@rchiodo Sorry if i was not clear, I was referring to a PyCharm-like debug console which is IPython. I tried all the above answers to have a simple matplotlib plot to show up while debugging, and it didn't work.

sedghi avatar Apr 29 '20 20:04 sedghi

The ability to drop into an IPython debug console anywhere is a very powerful tool, and is a real USP of PyCharm.

bashtage avatar Apr 29 '20 22:04 bashtage

I would also like to chime in here and say that this is really a big blocker for my department's adoption of VS Code.

hoechenberger avatar Apr 30 '20 09:04 hoechenberger

Looking for this feature as well

whong-art avatar May 14 '20 04:05 whong-art

@syagev don't know if this is what you want but it's kind of workaround and it's definitely ugly :) you can launch an embedded IPython REPL right from the DEBUG CONSOLE tab

    import IPython
    IPython.embed()

and interact with it at the TERMINAL tab.

Meanwhile - is there any way to automate this nice workaround?

Edit: I missed @bashtage's similar comment.

m-guggenmos avatar Jun 11 '20 11:06 m-guggenmos

is there any update here?

sedghi avatar Jul 21 '20 19:07 sedghi

This item is kinda ambiguous.

The original request was to support launch.json settings for the interactive window. That might happen. We don't have a definite plan for it though.

The other request was to allow the user to switch to an IPython terminal in the middle of debugging. That will likely never happen. Transferring kernel state (especially from a non kernel runtime) is non trivial and not something we're likely to pursue.

We might allow the user to start the debugger with IPython as a terminal though. Basically automate the workaround as described by @NetanelRabinowitz up above.

The status of this issue is waiting for @jmew or @claudiaregio to split it into those 3 parts.

rchiodo avatar Jul 21 '20 19:07 rchiodo

@rchiodo As I described in the previous comments, a very handy tool that PyCharm has is that it allows to plot in the middle of debugging which is super useful for different areas of image analysis especially in medical imaging. The IPython as a terminal with a workaround above does not allow for plotting of any kind.

sedghi avatar Jul 23 '20 15:07 sedghi

@sedghi you should be able to use the first option:

  • support launch.json settings for the interactive window.

You'd start the debugger using the interactive window. This should be possible now minus the settings (arguments to pass to the script etc).

rchiodo avatar Jul 23 '20 15:07 rchiodo

We might allow the user to start the debugger with IPython as a terminal though. Basically automate the workaround as described by @NetanelRabinowitz up above.

I think this is the closest to what PyCharm does. If you have IPython installed, when you drop into the console, you get an IPython session. There is no available to open as a standard Python session and then transform this to an IPython session.

bashtage avatar Jul 23 '20 15:07 bashtage

This item is kinda ambiguous.

I am entirely on board with moving forward with suggestion 1 and scratching suggestion 2. They were just ideas I had about how it could be implemented. The main end goal was just being able to use some sort of iPython-like console to debug - (and as others have suggested) mostly to allow for plotting capability within a debug breakpoint.

geophpherie avatar Jul 28 '20 03:07 geophpherie

I'd like to share my debugging workflow, as it is slightly different from OP's request.

It sometimes occurs to me that some functions misbehave and raise exceptions with a specific set of inputs which are generated in Python Interactive windows. It usually takes time to generate the inputs and I would love to have debugging tools at hand keeping the current kernel state. This would involve running a debugger from within Python Interactive, instead of exiting the Python Interactive window and running the debugger.

I realize this issue is about the opposite of what is discussed here: i.e. having a debugger within the Python Interactive window rather than a Python Interactive window within the debugger. Is this something which could be integrated with the solutions proposed here, or is it better to discuss in a new issue? I think this feature would really help me in switching to vscode. Thanks!

pepicello avatar Aug 04 '20 12:08 pepicello

@pepicello can you use the existing debug cell? We already have a way to start the debugger while using the interactive window.

rchiodo avatar Aug 04 '20 16:08 rchiodo