I would like to debug some of the basic packages that come with the Python install and/or are built-in packages, including pip and venv.
The desire comes from an error message of file permissions (unable to access a file with an "unprintable file name") some of my team is getting running these commands - see this question for details.
Question
How do you debug the Python source code when trying to catch issues in the main python executable, or when directly running a base python module (see following examples for pip and venv)?
$ python -m pip install --upgrade
$ python -m venv .venv
If it matters, my environment is VSCode, where I am happily able to engage the debugger on any custom script I have written, using the built-in debugger that interacts (I assume) with the main Microsoft Python extension.
pipis a pre-built binary, so if you want to debug that it's most likely going to involve modifying its source code directly and rebuilding the executable. Forvenv, the source appears to be located in the__init__.pyfile under<python_install>\lib\venv. In there, you could addimport pdb; pdb.set_trace()to start the Python DeBugger (or justbreakpoint(), which should work in VSCode).pip'executable' is just a Python script that uses thepkg_resourceslibrary to (indirectly) import thepip._internal.cli.mainmodule and runs themain()function in it. Open the path thatwhich pippoints to and you'll see it's just text you can add a debug statement to.site-packages) and I didn't considerpython -m pipwould suggest that it does exist as a module somewhere.