简体   繁体   English

VS Code:如何在调试时启动交互式 python 终端

[英]VS Code: How to launch an interactive python terminal while debugging

I have recently started using VS code for Python development.我最近开始使用 VS 代码进行 Python 开发。 I am unable to figure out how to launch an interactive terminal while debugging, with the program state loaded-in.我无法弄清楚如何在调试时启动交互式终端,并加载程序 state。 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.我想在C = A/B处设置一个断点,一旦断点命中,我想启动一个包含我程序的 state 的交互式终端。 So that I can play around with variables in the terminal.这样我就可以在终端中使用变量。

This is simple and straightforward in other Python IDEs like Spyder and Pycharm.这在 Spyder 和 Pycharm 等其他 Python IDE 中简单明了。 How do I do this with VS Code?如何使用 VS Code 做到这一点?

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.这个话题也困扰了我,所以我打开了一个功能请求,其中有人指出了调试控制台,它可以让你在调试时与 python 交互。

Do you mean the debug console tab?你的意思是调试控制台选项卡吗? It's usually a tab on the bottom of the VS Code screen.它通常是 VS Code 屏幕底部的一个选项卡。 在此处输入图像描述

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这是一个视频,其中展示了如何调试用 python 编写的服务器并使用调试控制台检查代码: https://youtu.be/O2Skmwns6o8?t=424

There's the Python debugging console in VSCode. VSCode中有Python调试控制台 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.当您的代码在断点处停止时,您可以单击调试控制台按钮打开交互式 Python 控制台,其中加载了当前程序 state。

VSCode 调试屏幕 - Microsoft Docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM