Recently, I found myself needing to debug the underlying functionality of the package dataset so that I could diagnose a connection leak that was occurring with my MariaDB. Seeing as my script obviously had to interact with the pip module at some point while debugging, I figured it should somehow be possible to breakpoint debug the package

I wasn't sure how easy it would be to accomplish this but luckily for us Visual Studio Code makes pip packages extremely easy to debug with a little bit of tweaking.

Getting started, you will need to locate where the pip package you want to debug is located on your drive. The easiest way to do this is via pip show dataset in Terminal like so:

As we can see, the "Location:" is the path where our package is installed on our drive.

Next, we will need to add the package to our workspace so that we can add our breakpoints to where we wish to debug. This can be done by going to "File" > "Add Folder to Workspace..." and selecting the Location folder containing your package.

Your workspace should look something like this afterwards:

Lastly, we'll need to make a small change to our .vscode\launch.json file so that we can debug pip packages. By default in Visual Studio Code, a feature called "Just My Code" is enabled which skips over external code while debugging. We want to disable this feature so that we can debug our package.

Your launch.json file is unique to your situation depending on your needs but to give an example, mine looked something like this:

We will need to disable Just My Code for the debug configuration we will be using. This can be done by setting "justMyCode" to false like so:

Now, you should be able to place your breakpoints in the source code of the package located in your workspace, run your debug configuration, and view the variables and call stack of your pip package!