Setting Up Python Debugger in VSCode. Install Python in Visual Studio Code, debug configuration, set up breakpoints, and understand different debugging actions in VSCode.

Setting Up Python Debugger in VSCode

Visual Studio Code is a lightweight but powerful cross-platform IDE that supports different programming languages. In this tutorial, we will talk about how to set up and run Python debugger in VSCode.

Resources for this post:

  • If you prefer the video version of the tutorial, watch the video below on YouTube.
Setting Up Python Debugger in VSCode – GrabNGoInfo.com

Let’s get started!

Step 1: Install Python in VSCode

Step 1.1: Click the Extensions icon on the left menu and type python in the search bar. Then click the results with the highest download number, and verify that the extension is published by Microsoft.

VSCode Install Python – GrabNGoInfo.com

Step 1.2: Click Install to install the extension. After the installation is completed, there will be options for Disable and Uninstall.

VSCode Install Python – GrabNGoInfo.com

Step 2: Open the Python File for VSCode Debugging

Step 2.1: Click the Explorer icon on the left menu and then click the blue Open Folder button.

VSCode Explorer Open Folder – GrabNGoInfo.com

Step 2.2: Select the project folder and open the python file for debugging.

VSCode Explorer Open Python File – GrabNGoInfo.com

Step 3: Run and Debug Python Code in VSCode

Step 3.1: Click the Run and Debug Icon on the left menu and add breakpoints by clicking the red dot in front of the row numbers.

VSCode Debug Add Breakpoints – GrabNGoInfo.com

Step 3.2: Click the blue Run and Debug button and select Python File for the Debug Configuration.

VSCode Python Debug Configuration – GrabNGoInfo.com

Step 3.3: We will see the debugging console showing on the left-hand side, and the program stops at the first break point.

VSCode Debugging Console – GrabNGoInfo.com

Step 4: Understand VSCode Debugging Actions

After the debugging session started, a toolbar with 6 action options appears.

VSCode Debugging Actions – GrabNGoInfo.com

  • The first action icon is Continue. It runs the code and stops at the next break point.
  • The second action icon is Step Over. It runs the code line by line and makes a stop after running each line of the code. If there is a function call, It returns the results directly without going through the code within the function.
  • The third action icon is Step In. It steps into the function if the code includes a function call. Otherwise, it runs the next line of code just like Step Over.
  • The fourth action icon is Step Out. After stepping into a function, we can use step out to get out of the function.
  • The fifth action icon is Restart. It restarts the debugging and stops at the 1st breakpoint.
  • The last action icon is Stop. It stops the debugging process.

For more information about data science and machine learning, please check out my YouTube channel and Medium Page or follow me on LinkedIn.

Recommended Tutorials

Leave a Comment

Your email address will not be published. Required fields are marked *