Let's consider the case where you're writing some incredibly important business logic in a simple environment and you want to see exactly what the pyjokes package is doing when you call get_joke().
from pyjokes import get_joke print(get_joke())
The package's Git repository is often a great place to start, but sometimes you want to be able to step through the package.
Here's what you can do:
- Activate your virtual environment (if you haven't already)
Uninstall the package
pip uninstall pyjokes
Reinstall the package from source with the editable flag
pip install --editable firstname.lastname@example.org:pyjokes/pyjokes.git#egg=pyjokes
--editablecan be shortened to
- You aren't limited to Git repositories! You can also use "svn+" and "bzr+" and a few others. See Pip's VCS support documentation
#egg=[Custom Name]creates a directory [Custom Name].egg.info relative to the project path. You probably won't care about this, but it's required.
The pyjokes repository can now be found in
[virtual environment folder name] > src > pyjokes. But this isn't exactly what we're interested in.
Find where the source code actually exists in the repository, in this case it's a subfolder with the same name. Sometimes it's a subfolder called "src".
[virtual environment folder name] > src > pyjokes > pyjokes
Move this folder up to the root level of your project. For example, this project directory now contains the following files and directories:
- pyjokes (folder)
- venv (virtual environment folder)
- Almost done! Set the breakpoints you want in the pyjokes source code, open business_logic.py, switch to the VSCode debugger and press the green run button. Two prompts will appear, select Python for the first and "current file" for the second!
As an added bonus, you can edit the package too--good luck debugging!