#DEBUGGING PYTHON IN VISUAL STUDIO FULL#
For full details on this feature in Visual Studio, see Breakpoint conditions. To set conditions, right-click the breakpoint's red dot, select Condition, then create expressions using Python code. You can customize the conditions under which a breakpoint is triggered, such as breaking only when a variable is set to a certain value or value range. This behavior is correct, even though it's sometimes surprising. If a breakpoint has been set, you may find the debugger breaking part-way through a class declaration. In Python, the entire file is executable code, so Python runs the file when it's loaded to process any top-level class or function definitions. Some breakpoints in Python can be surprising for developers who have worked with other programming languages. In any case, right-click the appropriate file and select Set as Startup File.
Visual Studio 2017 version 15.6 and later alerts you if you don't have a startup file set earlier versions may open an output window with the Python interpreter running, or the output window briefly appears and disappears. These actions launch your project's startup file (shown in bold in Solution Explorer) with the project's active environment and any command-line arguments or search paths that have been specified in Project Properties (see Project debugging options). The basic debugging workflow involves settings breakpoints, stepping through code, inspecting values, and handling exceptions as described in the following sections.Ī debugging session starts with the Debug > Start Debugging command, the Start button on the toolbar, or the F5 key.
#DEBUGGING PYTHON IN VISUAL STUDIO CODE#
To control the environment and arguments, create a project for the code, which is easily done with the From existing Python code project template. But from then on, you have full debugging support. With a stand-alone Python file open, right-click in the editor, select Start with Debugging, and Visual Studio launches the script with the global default environment (see Python environments) and no arguments. Python in Visual Studio supports debugging without a project.