Reputation: 423
When debugging my user code, I want to step into the code of a dependency that is installed e.g. with pip install -e path/to/package
.
I tried to find a place within the project where dependencies are listed and can be browsed to open the source file to debug (e.g. this is possible in PyCharm via the "External Libraries" section).
I would like to step into and through dependency code, but cannot find a way to do so.
Upvotes: 11
Views: 9148
Reputation: 774
Disable justMyCode
in the launch.json file. This is enabled by default.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "my_package",
"justMyCode": false
}
]
}
This helped me resolve issue on Studio Version: 1.63.2 (Universal)
Upvotes: 13
Reputation: 29580
It should be possible with the built-in debugging configuration. As far as I know, the only time it's not possible is when the Python dependencies are C codes (ex. OpenCV, pygame) because they are stored as .so files instead of Python files.
Let's say I have this structure:
main
└── test.py
pkgs
└── mypkg
├── __init__.py
├── moduleA.py
└── setup.py
I created mypkg
based on Packaging Python Projects sample from the Python docs. I then installed it on my env using the same command you mentioned:
pip install -e /path/to/mypkg
In test.py I have this:
import moduleA
moduleA.add_two_num(1, 2)
First, make sure to set the VSCode interpreter to use the same env where you installed mypkg
. See Select and activate an environment from the VSCode docs.
Next, create a debugging configuration for test.py:
{
"name": "test",
"type": "python",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "/path/to/test.py",
"pythonPath": "/path/to/.virtualenvs/test-py37/bin/python",
"console": "integratedTerminal",
}
It is important here again to set pythonpath
to point to the same python
where you installed mypkg
. Here I am using a virtualenv named test-py37
.
Now, set a breakpoint on the line with the external package:
Then start the debugger (press F5 or select it from the Debug panel then press the Play button). When the debugger stops at the breakpoint:
Just press the Step Into button (or F11) and VS Code should take you to the code for the external dependency. You can also open the file directly on VS Code, then put breakpoints on them. Once it's open on your editor, the next time you debug, it stops on those breakpoints.
Upvotes: 9