27

I have recently started using VS code for Python development. I am unable to figure out how to launch an interactive terminal while debugging, with the program state loaded-in . For example, consider the following code,

import numpy as np
A = np.array([1, 2, 3])
B = np.zeros()
C = A/B                  \\ <--- Breakpoint here

I want to set a breakpoint at C = A/B and as soon as the breakpoint hit, I want to launch an interactive terminal that holds the state of my program. So that I can play around with variables in the terminal.

This is simple and straightforward in other Python IDEs like Spyder and Pycharm. How do I do this with VS Code?

5
  • If you have VSCode's python plugin, it should only be a matter of marking the breakpoints by clicking on the left of the line number and running the main script with F5. Commented Jan 27, 2022 at 12:42
  • 1
    I am using the python extension, however, when the breakpoint hits, then the terminal is held up as well. It doesn't allow me to type anything or play around. Commented Jan 27, 2022 at 12:43
  • 6
    You should switch to the debug console tab Commented Jan 27, 2022 at 12:46
  • 2
    Check the last picture on this section: code.visualstudio.com/docs/python/… Commented Jan 27, 2022 at 13:35
  • Your question is strongly related to this one: stackoverflow.com/questions/65677725/… sadly without an working answer too. Commented Jul 25, 2022 at 12:03

6 Answers 6

27

There's the Python debugging console in VSCode. When your code stops on a breakpoint, you can click on the debug console button to open an interactive Python console with your current program state loaded in.

VSCode debugging screen - Microsoft Docs

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

4 Comments

more reasons to switch from PyCharm towards VS Code
@karamqusai why? PyCharm has the same, just next to the explorer, called "console". Actually, the Python interactive console in VScode, as proposed in this answer, doesn't show up for me
@KaramQusai the PyCharm implementation of this is a lot better: it allows searching in the output, keeps a searchable history of run commands, does auto-import on code completion...
I agree @pseudoDust but PyCharm is still expensive.
4

This Topic bugged me too, so I opened a feature request, where someone pointed the Debug-Console out which lets you interact with python at the point, where you're debugging.

Comments

3

Do you mean the debug console tab? It's usually a tab on the bottom of the VS Code screen. enter image description here

Here is a video where it shows how to debug a server written in python and goes over the code using debug console: https://youtu.be/O2Skmwns6o8?t=424

Comments

3

I faced the same issue. The reason I could not find the debug console was that it was hidden. From the explorer tab, click on the top right three buttons (...) and check the debug console.

Comments

1

control+shift+Y (refer dash line in the image below)

View debug console

vscode version 1.86

Comments

0

Make sure a folder is opened in VSCode and run the following in the terminal:

debugpy file.py

There are some caveats for this to work. Check this link: No-Config-Debugging

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.