Debugging configurations for Python applications in Visual Studio Code (2023)

The Python extension supports debugging various types of Python applications. For a quick guide to basic debugging seeTutorial - Set up and run the debugger. also seeBottle guide. Both tutorials demonstrate basic skills such as setting breakpoints and stepping through code.

For general debugging functions such as checking variables, setting breakpoints, and other non-language-specific activities, seeFoutopsporingscode VS.

This article is mostly about Python-specific debuggingconfigurationsincluding the necessary steps for certain types of applications and remote debugging.

Initialize configurations

The configuration determines the behavior of VS code during a debugging session. Configurations are defined in arun.jsonthe file in which it is saved.vscodefolder in your workspace.

Remark: To change the debug configuration, your code must be stored in a folder.

First, select the file to run the debug configurationsStartsidebar view:

Debugging configurations for Python applications in Visual Studio Code (1)

If you haven't defined any configuration yet, you will see a button to do soRun and debugand the link to create the configuration file (launch.json):

Debugging configurations for Python applications in Visual Studio Code (2)

generaterun.jsonpython configuration file, follow these steps:

  1. Choosecreate a launch.json filelink (shown in the image above) or useStart>Open configurationsmenu command.

  2. The configuration menu opens from the command palette, allowing you to select the type of debug configuration for the open file. for nowSelect a configuration to debugselect from the menu that appearspython zaliha.Debugging configurations for Python applications in Visual Studio Code (3)

    Remark: Start a debug session from the debug panel,F5LubRun > Start Debuggingif there is no configuration, the debug configuration menu is also displayed, but no launch.json file is created.

  3. Then the python extension creates and opens the filerun.jsonfile with a predefined configuration based on what you selected earlier, in this casepython zaliha. You can change configurations (for example to add arguments) and add custom configurations.

    Debugging configurations for Python applications in Visual Studio Code (4)

Configuration properties are discussed in detail in a section later in this articleStandard configuration and options. Other configurations are also described in this articleDebugging specific types of applications.

Additional configurations

By default, VS Code only displays the most common Python extension configurations. You can choose other recording configurationsrun.jsondoorAdd configurationnaredba shown in lists irun.jsoneditor. When you use the command, VS Code prompts you for a list of all available configurations (don't forget to include thePythonChoice):

Debugging configurations for Python applications in Visual Studio Code (5)

ChoiceJoin process IDone gives the following result:Debugging configurations for Python applications in Visual Studio Code (6)

SeeDebugging specific types of applicationsfor more information on all these configurations.

During debugging, the status bar shows the current configuration and the current debug interpreter. Selecting a configuration displays a list from which you can select another configuration:

Debugging configurations for Python applications in Visual Studio Code (7)

By default, the debugger uses the same interpreter selected for your workspace as other Python extension functions for VS Code. To use a different debug interpreter, set the value toPythonWrun.jsonfor correct debugging configuration. You can also select the named translator in the status bar to choose another.

Basic debugging

If you're just interested in debugging a python script, the easiest way is to select the down arrow next to the Run button in the editor and selectDebug python file in terminal.

(Video) Debugging Python in VSCode - 01 - Intro to Debugging in VSCode

Debugging configurations for Python applications in Visual Studio Code (8)

If you want to debug a web application using Flask, Django, or FastAPI, the Python extension provides dynamically created debugging configurations based on the structure of your project inShow all auto-debug configurationsoption, throughRun and debugdisplay.

Debugging configurations for Python applications in Visual Studio Code (9)

But if you want to debug other types of apps, you can run the debugger with the fileStartsee by clickingRun and debugbutton.

Debugging configurations for Python applications in Visual Studio Code (10)

If no configuration is set, a list of debugging options is displayed. Here you can choose the right option to quickly debug your code.

Two common options are to usepython zalihaconfiguration to run or use the currently open python fileJoin process IDconfiguration to associate the debugger with a process that is already running.

For information about creating and using debug configurations, seeInitialize configurationsandAdditional configurationssections. After adding a configuration, you can select it from the drop-down list and start using itStart debuggingbutton.

Debugging configurations for Python applications in Visual Studio Code (11)

Command line debugging

You can also run the debugger from the command line. The debug command line syntax is as follows:

piton -m fotosporing--listen | --combine[:][--wait-for-customer][--configuration- ]...[--log-to] [--log-to-stderr]| -M| -C| --pid[]...

For example, you can run the debugger from the command line with a specific port (5678) and a script with the following syntax. This example assumes that the script has been running for a long time and has been skipped--waiting for the customerflag, which means the script does not wait for the client to connect.

python -m debuppy --listen 5678 ./

Then use the following recording configuration from the VS Code Python extension.

{ "to do":"Python: Join Us", "tip":"Python", "Application":"attach", "combine": { "host":"Local Host", "Asylum":5678}}

Remark: Specifying a host is optional forListen, by default the address is used.

To debug remote code or code running in a docker container on a remote machine or container, you must modify the previous CLI command to specify the host.

python -m debuppy --listen ./

The associated configuration file then looks like this.

{ "to do":"Attach", "tip":"Python", "Application":"attach", "combine": { "host":"remote-computer-name",// replace this with the remote hostname "Asylum":5678}}

Remark: Note that if you specify a host value that is not127.0.0.1LubLocal hostopen a port to allow access from any machine, which creates security risks. If you are debugging remotely, make sure you take the appropriate precautions, such as using an SSH tunnel.

--ListenLub--combine[:]Required. Specifies the host address and port on which the debugger adapter server should listen for incoming connections (--listen) or connect to a client that is listening for incoming connections (--connect). This is the same address used in the VS code debug configuration. The default is the host addresslocalhost (
--waiting for the customercousinoptional. Specifies that code should not be executed until a connection is established from the debug server. This setting allows you to debug from the first line of code.
--log-dooptional. Specifies the path to an existing directory to store records.
--log-do-stderrcousinoptional. Allows debugpy to write logs directly to stderr.
--pidoptional. Specifies the process that is already running to inject the debug server.
--configure-optional. Sets a debug property that must be known to the debug server before the client connects. Such properties can be used directly instartconfiguration but must be set this way forencloseconfigurations. For example, if you don't want the debug server to automatically inject itself into subprocesses created by the process you're connecting to, use--configure-subProcess False.

Remark:[]can be used to pass command line arguments to the running application.

Troubleshooting by connecting over a network connection

Fout tracking in local scripts

Sometimes you will need to debug a Python script that is called locally by another process. For example, you can debug a web server that runs different python scripts for specific processing tasks. In these cases, you should include the VS Code debugger in the script after you run it:

  1. Start VS Code, open the folder or workspace that contains the script, and createrun.jsonfor that workspace, if it doesn't already exist.

  2. Add the following to the script code and save the file:

    importdebugging#5678 is the default plugin to include in VS code debug configurations. Unless host and port are specified, the default host is print("Waiting for debugger to connect")debuppy.wait_for_client()debuppy.breakpoint()to print("break this rule")
  3. Open terminal sTerminal: Create a new terminal, which activates the selected scripting environment.

  4. In the terminal, install the debug package withpython -m pip install --upgrade debugpy.

  5. For example, in the terminal, run python with the scriptpython3 mó You should see "Waiting for debugger to be attached", which is included in the code, and the script stops atdebuppy.wait_for_client()phone call.

  6. Switch toRun and debugdisplay (⇧⌘D(Windows, LinuxCtrl+Shift+D)), select the appropriate configuration from the Debugger drop-down list and start the debugger.

  7. The debugger should stop atdebuppy.breakpoint()calls, from then on you can use the debugger normally. You also have the option to set other breakpoints in the script code via the UI instead of using themdebuppy.breakpoint().

Remote script debugging using SSH

Remote debugging allows you to step through a program locally in VS Code while it is running on a remote computer. There is no need to install VS Code on the remote computer. For added security, you may need a secure connection, such as SSH, to the remote computer while debugging.

(Video) How to get the python debugger working in VScode

Remark: Installation may be required on Windows computersWindows 10 OpenSSHhavesshTeams.

The steps below show the general procedure for setting up an SSH tunnel. An SSH tunnel allows you to work on your local computer as if you were working directly on a remote computer, more secure than opening a port for public access.

On the remote computer:

  1. Enable port forwarding by opening the filesshd_configconfiguration file (in/etc/ssh/on Linux and below%programfiles(x86)%/openssh/etcin Windows) and add or change the following setting:

    Allow tcp forwarding yes

    Remark: The default value for AllowTcpForwarding is yes, so you may not need to make any changes.

  2. If you want to add or changeAllow tcp forwarding, restart the SSH server. Running on Linux/macOSsudo restarts the ssh service; run on Windowsusluge.mscselect OpenSSH ilissdin the list of services and selectRestart.

On the local computer:

  1. Create an SSH tunnel by runningssh -2 -L source port: localhost: destination port -i identity file user@remoteaddressuse the selected port forport of destinationand the associated username and IP address of the remote computerremote user@address. For example, to use port 5678 on IP address, the command would be:ssh -2 -L 5678:localhost:5678 -i identiteitsbestand gebruiker@ You can specify the path to the identity file using-andflag.

  2. Check if you see the prompt in the SSH session.

  3. In your VS Code workspace, create a remote debugging configuration filerun.jsonfile by setting the port to match the port used in the filesshcommand and host forLocal host. you useLocal hosthere because you set up an SSH tunnel.

    { "to do":"Python: Join Us", "tip":"Python", "Application":"attach", "Asylum":5678, "host":"Local Host", "Pictures of the Road": [{ "local root":"${workspaceFolder}",// Tabs C:\Users\user1\project1 "external root":"." // To the current working directory ~/project1}]}

Debugging start

Now that the SSH tunnel is set up on the remote computer, you can start debugging.

  1. Both computers: Make sure identical source code is available.

  2. Both computers: installdebuggingdoorpython -m pip install --upgrade debugpyyour environment (although using some form of virtual environment is not required, it is a recommended best practice).

  3. Remote computer: There are two ways to specify how you want to connect to the remote process.

    1. In your source code, add the following lines by replacing themAddresswith the IP address and port number of the remote computer (the IP address is shown here for illustrative purposes only).

      importdebugging# Allow other computers to connect for debugging on this IP address and port.debuppy.listen(("",5678))# Pause the program until the external debugger is connecteddebuppy.wait_for_client()

      IP address used inListenmust be the private IP address of the remote computer. You can then run the program normally and pause it until you add the debugger.

    2. Start a remote process with debuppy, for example:

      python3 -m debuppy --listen --wait for client -m mijn project

      This will launch the packagemy projectdoorpython3, with the private IP address of the remote computer1.2.3.4and listen at the port5678(you can also start a remote python process by specifying the file path instead of the-M, As./cześć.py).

  4. local computer:Only if you have modified the source code on the remote computer as described above, then add to the source code a commented copy of the same code that you added on the remote machine. Adding these lines ensures that the source code on both machines matches line by line.

    #photo tracking import# Allow other computers to connect for debugging on this IP address and port.#debuppy.listen(('', 5678))# Pause the program until the external debugger is connected#debuppy.wait_for_client()
  5. Local computer: Switch toRun and debugdisplay (⇧⌘D(Windows, LinuxCtrl+Shift+D)) in Select VS codePython: Join usconfiguration

  6. Local Machine: Set a breakpoint in your code where you want to start debugging.

  7. Local machine: Run the VS code debugger with ModifiedPython: Join usconfiguration and the Start Debugging button. VS Code should stop at locally set breakpoints, allowing you to step through your code, inspect variables, and perform any other debugging actions. Expressions you enterDebug consolethey are also executed on the remote computer.

    Text output to stdout, fromto printstatement, appears on both computers. However, other output, such as graphical plots from packages such as matplotlib, only appear on the remote computer.

  8. During remote debugging, the debug toolbar looks like this:

    Debugging configurations for Python applications in Visual Studio Code (12)

    (Video) How To Debug Python Code In Visual Studio Code (VSCode)

    On this toolbar, the Disconnect button (⇧F5(Windows, LinuxShift+F5)) stops debugging and allows the remote program to run completely. Restart button (⇧⌘F5(Windows, LinuxCtrl+Shift+F5)) restarts the debugger on the local computer, but it doesBORNrestart the program remotely. Use the restart button only if you have already restarted the remote program and need to reconnect the debugger.

Set configuration options

When you first createrun.json, there are two default configurations that run the active file in the editor on the integrated terminal (inside VS Code) or the remote terminal (outside VS Code):

{ "configurations": [{ "to do":"Python: current file (integrated terminal)", "tip":"Python", "Application":"start", "plan":"${stock}", "comfort":"integrated terminal"},{ "to do":"Python: huidig ​​inventory (external terminal)", "tip":"Python", "Application":"start", "plan":"${stock}", "comfort":"External terminal"}]}

Specific settings are described in the following sections. You can also add other settings such asargumentswhich are not included in standard configurations.

Advice: In a project, it is often useful to create a configuration that executes a specific startup file. For example, if you always want to runstart.pywith arguments-- luka 1593after running the debugger, create a configuration entry like this:

{ "to do":"Python:", "tip":"Python", "Application":"start", "plan":"${workspaceFolder}/", "arguments": ["--Asylum","1593"]},

To do

Contains the debug configuration name that appears in the VS Code drop-down list.


Identifies the type of debugger being used; exit this settingPythonfor python code.


Specifies how to start debugging:

  • start: starts the debugger on the file specified inplan
  • enclose: add a debugger to an already running process. To seeRemote debuggingFor example.


Provides a fully qualified path to the Python input module (startup file). Value${stock}, which is often used in default configurations, uses the currently active file in the editor. By specifying a specific startup file, you can always ensure that the program starts from the same starting point, regardless of which files are open. For example:


You can also rely on the relative path from the root of the workspace. For example as root/Users/Me/Projects/PokemonGo-Botthen you can use the following example:



Provides the ability to specify the name of a debug module, such as with-Margument when run on the command line. For more information


The full path to the Python interpreter used for debugging.

If not specified, this setting defaults to the interpreter selected for the workspace, which is equivalent to using a value${command:python.interpreterPath}. To use another interpreter, specify the path in the filePythondebug configuration property.

You can also use a custom environment variable defined on each platform to include the full path to the Python interpreter you are using, eliminating the need for other directory paths.

If you need to pass arguments to the python interpreter, you can use a methodpythonArgsproperty.


Specifies the arguments to pass to the Python interpreter using the syntax"pythonArgs": ["", "",...].


Specifies the arguments to pass to the Python program. Each element of the argument string, separated by a space, must be enclosed in quotation marks, for example:

"arguments": ["--Calm","--don't repeat","--Asylum","1593"],


When set toWHERE, terminates the debugger on the first line of the debugger. If omitted (default) or set toLIE, the debugger runs the program to the first breakpoint.


Determines how the program output is displayed, as long as it is set by defaultredirectOutputhave not been changed.

ValueWhere the output is displayed
"internal console"VS Code-foutopsporingsconsole.IredirectOutputset to False, no output is displayed.
"integrated terminal"(standard)Terminal integrated with VS kodom. IredirectOutputset to True, the output is also displayed in the debug console.
"External terminal"A separate console window. IredirectOutputset to True, the output is also displayed in the debug console.


There is more than one way to configure itStartuse the buttonintentionChoice. Set options tofault finding test, specifies that the configuration should be used when debugging tests in VS Code. However, if you set the option toterminal debugging, indicates that the configuration should only be used on openingRun the python filein the upper right corner of the editor (regardless of whetherRun the python fileLubDebug python-bestandbutton options are used).Remark:intentionoption cannot be used to run the debuggerF5LubRun > Start Debugging.

automatic reloading

It allows the debugger to automatically reload after a code change after the execution of the debugger reaches a breakpoint. To enable this feature set{"enable": true}as shown in the code below.

{ "to do":"Python: huidig​​​​consisted", "tip":"Python", "Application":"start", "plan":"${stock}", "comfort":"integrated terminal", "load automatically": { "clutch":WHERE}}

*Remark: When the debugger is reloaded, the code running during the import can be executed again. To avoid this situation, you can try to use only imports, constants and definitions in your module and put all your code in functions. Alternatively, you can also useif __name__=="__head__"control.


Specifies whether subprocess debugging should be enabled. DefaultLIE, Set upWHEREallow. For more information seedebugging on multiple targets.


Specifies the current working directory for the debugger, which is the base directory for all relative paths used in the code. If omitted by default${workspaceFolder}(open karte u VS kodu).

Let's say as an example${workspaceFolder}containscode_pycontain folderaplikacija.pyIAdeencontain foldersalary.csv. When you start the debuggerpy_code/, the relative paths to the data file vary depending on the valuecwd:

cwdRelative path to the data file
omitted or${workspaceFolder}data/salary.csv


When set toWHERE(defaults to innerConsole) causes the debugger to print all program output to the VS Code Debug output window. If set toLIE(default for IntegratedTerminal and externalTerminal), program output is not displayed in the debugger output window.

This option is usually disabled when used"console": "integrated terminal"Lub"console": "External Terminal"because there is no need to duplicate the output in the debug console.

(Video) How to Debug Python with VSCode


After skipping or settingWHERE(default), limits debugging to user-written code only. setLIEto also enable debugging of standard library functions.


When set toWHERE, activates debugging features specific to the Django web framework.


When set toWHEREand is used with"console": "External Terminal", allows you to debug applications that require privilege escalation. You must use a remote console to intercept the password.


When set toWHERE, launches the Pyramid appneededkeepTeams.


Sets optional environment variables for the debugging process in addition to the system environment variables that the debugger always inherits. The values ​​of these variables must be entered as strings.

file env

Optional path to the file containing the environment variable definitions. SeeConfiguring the Python environment - environment variable definition file.


If set toWHERE, enables debuggingvent monkey patched code.


When set toWHERE, activates program-specific debugging functionsJinjatemplate frames.

Breakpoints and logarithmic points

Python extension supportsbreaking pointsandapplication pointsto debug the code. For a quick guide to basic debugging and using breakpoints, seeTutorial - Set up and run the debugger.

Conditional breakpoints

Breakpoints can also be triggered based on an expression, the number of hits, or a combination of both. The Python extension supports the number of hits that are integers in addition to integers preceded by ==, >, >=, <, <=, and %. For example, you can set a breakpoint to fire after five hits by setting the number of hits to>5For more information seeconditional breakpointsin the main VS Code Debugging article.

Trigger a breakpoint in your code

In your python code you can calldebuppy.breakpoint()when you want to pause debugging during a debugging session.

Breakpoint check

The python extension automatically detects breakpoints set on non-executable rules such aspassagestatements or the middle of a multiline statement. In these cases, running the debugger moves the breakpoint to the nearest valid line to stop code execution at that point.

Debugging specific types of applications

The configuration drop-down list contains several options for common application types:

EncloseSeeRemote debuggingin the previous section.
DjangoIt defines"program": "${workspaceFolder}/","args": ["runtime-server"]. He also adds"django": trueto enable debugging of Django HTML templates.
YesSeeDebugging in the bottleunder.
BleedHe adds"give": trueto a standard integrated terminal configuration.
PyramidRemovesplanhe adds"args": ["${workspaceFolder}/development.ini"]he adds"jinja": truthto enable debugging and template additions"pyramid": trueto ensure that the program works withneededkeepTeams.

Special steps are also required for remote debugging and Google App Engine. For more information about debugging tests, seeTest.

To debug an application that requires administrative privileges, use"console": "External Terminal"and"sudo": "Where".

Debugging in the bottle

{ "to do":"Python: Kolba", "tip":"Python", "Application":"start", "module":"tracking", "Environment": { "FLASK_APP":""}, "arguments": [ "start", "--no debugger"], "jinja":WHERE},

As you can see, this specifies the configuration"env": {"FLASK_APP": ""}and"args": ["pokreni", "--no-debugger". From"module": "bat"property is used insteadplan. (You can see"FLASK_APP": "${workspaceFolder}/"wgoproperty, in which case the configuration is changed to refer only to the filename. Otherwise, you may see the error "Failed to import module C", where C is the drive letter.)

From"jinja": truththis setting also allows you to debug Jinja Flask's default templating engine.

To run the Flask development server in development mode, use the following configuration:

{ "to do":"Python: Flask (Developer Mode)", "tip":"Python", "Application":"start", "module":"tracking", "Environment": { "FLASK_APP":"", "KOLBA_ENV":"development"}, "arguments": [ "start"], "jinja":WHERE},

Solve the problem

There are many reasons why the debugger does not work. Sometimes the debug console reveals specific reasons, but the main reasons are as follows:

  • The path to the Python executable file is incorrect: check the path of the selected interpreter by running the filePython: Choose an interpretercommand and see the current value:

    Debugging configurations for Python applications in Visual Studio Code (13)

  • There are invalid expressions in the monitor window: clear all expressions in the monitor window and run the debugger again.

  • If you are working with a multi-threaded application that uses the native threading API (such as Win32Create a threadinstead of Python's threading API), it is now necessary to place the following source code at the beginning of each file you want to debug:

  • Ako radite saLinuxWhen you try to apply the debugger to a running process, you may get a "timed out" error. To avoid this, you can temporarily run the following command:

    Go0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

Next steps

  • Python environments- Specify which python interpreter is used for editing and debugging.
  • Test- Set up test environments and discover, run and debug tests.
  • Item reference- Explore the full range of Python-related settings in VS Code.
  • General troubleshooting- Learn more about VS code debugging features.



How do I Debug a Python application in Vscode? ›

If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.

How do I set Debug configuration in Vscode? ›

Alternatively, you can run your configuration through the Command Palette (Ctrl+Shift+P) by filtering on Debug: Select and Start Debugging or typing 'debug ' and selecting the configuration you want to debug. In addition, the debug status appears in the Status Bar showing the active debug configuration.

How to configure Python on Visual Studio code? ›

Was this documentation helpful?
  1. Prerequisites.
  2. Install Visual Studio Code and the Python extension.
  3. Install a Python interpreter.
  4. Verify the Python installation.
  5. Start VS Code in a workspace folder.
  6. Select a Python interpreter.
  7. Create a Python Hello World source code file.
  8. Run Hello World.

How to fix the Python path in your Debug configuration is invalid? ›

My Case: I couldn't find the underlying reason, but could find a workaround as follows.
  1. Do not use Run -> Start Debugging (or Run -> Run without Debugging). This raises the problem.
  2. Instead, open the terminal. Change directory to where your python file is. Then, do command such as "python".
Mar 18, 2021

How do I debug a Python application? ›

Execute the statement (given as a string or a code object) under debugger control. The debugger prompt appears before any code is executed; you can set breakpoints and type continue , or you can step through the statement using step or next (all these commands are explained below).

How to debug a Python program? ›

There are two ways to invoke pdb :
  1. Call pdb externally. To call pdb when on a terminal you can call it while executing your . py file. ...
  2. Add a breakpoint with pdb. There can be cases when you get a false positive(s) in a test. Your test case might pass but you don't get the data you were expecting.
Sep 27, 2022

How to configure in Visual Studio code? ›

Set up Visual Studio Code
  1. Download and install VS Code.
  2. Create a new file.
  3. See an overview of the user interface.
  4. Install support for your favorite programming language.
  5. Change your keyboard shortcuts and easily migrate from other editors using keymap extensions.
  6. Customize your editor with themes.

How to set Python environment in Visual Studio? ›

Right-click Python Environments in Solution Explorer and select Add Environment. In the Browse dialog that appears, navigate to and select the folder that contains the virtual environment, and select OK. If Visual Studio detects a requirements. txt file in that environment, it asks whether to install those packages.

Is VS Code good for Python? ›

VS Code comes with great debugging support for Python, allowing you to set breakpoints, inspect variables, and use the debug console for an in-depth look at how your program is executing step by step. Debug a number of different types of Python applications, including multi-threaded, web, and remote applications.

Can we practice Python on Visual Studio code? ›

Visual Studio Code is a free source code editor that fully supports Python and useful features such as real-time collaboration. It's highly customizable to support your classroom the way you like to teach.

How do I fix Python path configuration? ›

Path will be set for executing Python programs.
  1. Right click on My Computer and click on properties.
  2. Click on Advanced System settings. ...
  3. Click on Environment Variable tab.
  4. Click on new tab of user variables. ...
  5. Write path in variable name.
  6. Copy the path of Python folder.
  7. Paste path of Python in variable value.

How to debug Python code in IDE? ›

If you want to run your code with the built-in debugger, then you'll need to turn this feature on. To do so, select Debug → Debugger from the Python IDLE menu bar. In the interpreter, you should see [DEBUG ON] appear just before the prompt ( >>> ), which means the interpreter is ready and waiting.

How do you debug or troubleshoot errors in Python? ›

Find & Fix Code Bugs in Python: Debug With IDLE
  1. Step 1: Make a Guess About Where the Bug Is Located.
  2. Step 2: Set a Breakpoint and Inspect the Code.
  3. Step 3: Identify the Error and Attempt to Fix It.
  4. Step 4: Repeat Steps 1 to 3 Until the Bug Is Gone.
  5. Alternative Ways to Find Bugs.

How do I debug an application in Visual Studio? ›

To debug, you need to start your app with the debugger attached to the app process. To do this: Press F5 (Debug > Start Debugging), which is the most common method.

How do I debug an application code? ›

General debugging procedure
  1. Define where the program needs to be stopped. This is done using breakpoints. ...
  2. Run your program in debug mode. ...
  3. After the program has been suspended, use the debugger to get the information about the state of the program and how it changes during running.
Mar 5, 2023

How to Debug Python in Visual Studio? ›

Select the Tools > Options menu command, navigate to Python > Debugging, and select the Use legacy debugger option. If you've installed an older version of ptvsd in the current environment (such as an earlier 4.0. x version, or a 3. x version required for remote debugging), Visual Studio may show an error or warning.

What are the two categories of errors when debugging code in Python? ›

Debugging in any programming language typically involves two types of errors: syntax or logical.

Is it hard to Debug Python? ›

But when it comes to Python, debugging “out of the box” is a little bit cruder and primitive; single-step debugging is the main way to debug Python code, and is quite slow and clunky. It's just easier to use print statements; Python founder Guido van Rossum (reportedly) uses them for 90 percent of his debugging.

How do I use breakpoint in Visual Studio code? ›

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

How to pass command line arguments in Python Visual Studio Code? ›

To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.

What are debug settings? ›

A debug menu or debug mode is a user interface implemented in a computer program that allows the user to view and/or manipulate the program's internal state for the purpose of debugging.

How do I manage configurations in Visual Studio? ›

You can use the Configuration Manager dialog box to select or modify existing build configurations, or to create new ones. To open the Configuration Manager dialog box, in Solution Explorer, right-click on the solution node to open the shortcut menu for the solution, and then choose Configuration Manager.

How do I add system configuration in Visual Studio? ›

Configuration Assembly to the project in the following way.
  1. Right click on the project and click Add Reference option from the Context Menu.
  2. From the Add Reference dialog box, click on . Net Tab and look for System. ...
  3. Once the reference is added, it will be shown in the References folder of the Solution Explorer.
Dec 9, 2014

What are the different types of settings available in Visual Studio code? ›

  • Overview.
  • Activity Bar.
  • Sidebars.
  • Panel.
  • Status Bar.
  • Views.
  • Editor Actions.
  • Quick Picks.

How do I set debug path in Visual Studio? ›

Right-click on the project node in Solution Explorer and select Properties. Expand the Build section, and select the Output subsection. Find the Base output path for C#, and type in the path to generate output to (absolute or relative to the root project directory), or choose Browse to browse to that folder instead.

How to use a debug build configuration or disable the debug option enable just my code? ›

To enable or disable Just My Code in Visual Studio, under Tools > Options (or Debug > Options) > Debugging > General, select or deselect Enable Just My Code.

How do I run a script in debug mode? ›

The most common is to start up the subshell with the -x option, which will run the entire script in debug mode. Traces of each command plus its arguments are printed to standard output after the commands have been expanded but before they are executed. This is the script ran in debug mode.

How to setup Python and Python virtual environment? ›

To create a virtual environment, go to your project's directory and run venv. If you are using Python 2, replace venv with virtualenv in the below commands. The second argument is the location to create the virtual environment. Generally, you can just create this in your project and call it env .

How do I set Python environment in Python? ›

To set and get environment variables in Python you can just use the os module: import os # Set environment variables os. environ['API_USER'] = 'username' os. environ['API_PASSWORD'] = 'secret' # Get environment variables USER = os.

How do you set a coding environment in Python? ›

If you already have a development environment set up, see Python and Google Cloud to get an overview of how to run Python apps on Google Cloud.
  1. Objectives. ...
  2. Installing Python. ...
  3. Using venv to isolate dependencies. ...
  4. Installing an editor. ...
  5. Installing the Cloud Client Libraries for Python. ...
  6. Installing the gcloud CLI. ...
  7. What's next.

What is the difference between VS Code and Visual Studio? ›

“Visual Studio” and “Visual Studio Code” are not the same thing. Visual Studio is an integrated development environment (IDE) and Visual Studio Code is a rich text editor like Sublime Text and Atom.

Which is better PyCharm or Visual Studio Code for Python? ›

PyCharm is the way to go if you want a powerful, focused, and well-configured Python development environment. However, VS Code is preferred if you want something lightweight with the ability to customize. Both are excellent tools that, depending on how you choose to utilize them, can be used for a variety of tasks.

Is it better to use PyCharm or VS Code? ›

Visual Studio Code has a larger extension ecosystem, thus making it more customizable and versatile. PyCharm has a smaller ecosystem, but it comes with more features. VS Code has IntelliSense to save you from typing. In addition, it has a GitHub CoPilot extension that makes coding faster.

Why use PyCharm over VS Code? ›

PyCharm boasts more features, such as a debugger, profiler, and test runner that come standard, while VS Code requires extensions to access these tools. PyCharm is a commercial product and requires a paid license for full functionality, while VS Code is open-source and free to use.

How do I debug a Python unit test in Visual Studio? ›

To start debugging, set an initial breakpoint in your code, then right-click the test (or a selection) in Test Explorer and select Debug Selected Tests. Visual Studio starts the Python debugger as it would for application code.

How do I debug a Jupyter notebook in VS Code? ›

Start by setting any breakpoints you need by clicking in the left margin of a notebook cell. Then select the Debug Cell button in the menu next to the Run button. This will run the cell in a debug session, and will pause on your breakpoints in any code that runs, even if it is in a different cell or a .py file.

How do I Debug a console application in Visual Studio code? ›

While not currently debugging, and focus is on Visual Studio:
  1. Choose Debug > Step Into. ...
  2. Press F11 . ...
  3. Press F11 . ...
  4. Respond to the prompt by entering a string in the console window and pressing Enter . ...
  5. Press F11 . ...
  6. Press F11 . ...
  7. Press F11 . ...
  8. Choose Debug > Step Out.
Jan 25, 2023

How do I Debug a terminal application in Visual Studio code? ›

Step through a program
  1. Set a breakpoint on the opening curly brace of the Main method.
  2. Press F5 to start debugging. ...
  3. Select Run > Step Into or press F11 . ...
  4. Select Run > Step Into or press F11 . ...
  5. Select Run > Step Into or press F11 . ...
  6. Respond to the prompt by entering a string in the Terminal tab and pressing Enter .
Jan 25, 2023

How do I unit test my Python code? ›

Using Unittest
  1. Firstly, we have to import unittest as standard.
  2. Create a class called TestAdd that inherits from the TestCase class.
  3. Change the test functions into methods.
  4. Change the assertions to use the self. assertEqual() method in the TestCase class. ...
  5. Change the command-line entry point to call unittest.main()
Apr 29, 2022

How do I run a unit test in Python Vscode? ›

Running Unit Tests in Visual Studio Code

Click on the button labeled Configure Python Tests. A dropdown menu will appear at the top of the screen. From here, select unittest. Next, click on the option that is labeled with the directory of the tests.

How do you debug unit tests in Vscode? ›

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

What are the three ways to step through the code while debugging? ›

There are several ways you can tell the debugger to move through the code:
  • Step (or Step In) Complete the next line of code. ...
  • Step Over. Stepping over means to move to the next line of code in the current function. ...
  • Step Out.

What does IDE mean in Python? ›

An integrated development environment (IDE) is a software application that helps programmers develop software code efficiently.

How to Debug Python code without IDE? ›

Directly use command python without -m pdb to run the code. The program will automatically break at the position of pdb. set_trace() and enter the pdb debugging environment. You can use the command p variable to view the variables or use the command c to continue to run.

How do I Debug Python code in Jupyter? ›

Debug code in Jupyter notebooks
  1. Set the breakpoints in the selected cell and press Alt + Shift + Enter for Windows or ⌥⇧↩ for macOS. ...
  2. Use the stepping toolbar buttons stepping toolbar to choose on which line you want to stop next and switch to the Debugger tab to preview the variable values:
Mar 23, 2023

What is the difference between Python script and Jupyter Notebook? ›

While a regular Python script has to reload the entire dataset on each execution, a Jupyter Notebook lets you run the cell responsible for loading the data once. You can then create new cells to work with the data without ever needing to reload it.


1. Debugging Python with Visual Studio Code (VSCode)
2. Python debug configurations for Masonite Framework in Visual Studio Code
(Marcelo Honorio)
3. Configure and Run Debugger on Python program in Visual Studio Code | Beginner's Tutorial
(Cool IT Help)
4. Powerful VSCode Tips And Tricks For Python Development And Design
5. Python Debugging in VS Code
6. How To Setup VS Code for Debugging C, C++, and Python
Top Articles
Latest Posts
Article information

Author: Velia Krajcik

Last Updated: 06/23/2023

Views: 5253

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.