vscode-jupyter
vscode-jupyter copied to clipboard
Jupyter cell debugging does not support "step into" the third party library code with "justmycode:false"
Jupyter cell debugging does not support "step into" the third party library code with "justmycode:false" in launch.json.
Please fix it !
can not step into lib code even setting: "jupyter.debugJustMyCode": false
This is explicitly hardcoded here:
https://github.com/microsoft/vscode-jupyter/blob/350a17c56b64317788b269f618b24ef112806eaa/src/client/debugger/jupyter/debuggingManager.ts#L299
Likely because stepping into 3rd party code isn't going to do what you want. It will end up stepping through the display hooks for ipython and not the 3rd party library.
@int19h is there a way to add libs to the 'justMyCode' list?
I don't think we have anything documented for this, but pydevd exposes some environment variables to control this. Presumably you'd want the library to debug to be listed in IDE_PROJECT_ROOTS
, but I'm not sure how this will interact with the default exclusion filters - @fabioz should know.
I wonder if perhaps the Jupyter extension should be using the exclusion filters on a lower level to specifically exclude all those display hooks, while leaving "justMyCode" setting to the user?
I wonder if perhaps the Jupyter extension should be using the exclusion filters on a lower level to specifically exclude all those display hooks, while leaving "justMyCode" setting to the user?
That sounds interesting too. How do we set exclusion filters?
It's all in the same code linked above, so currently, also via env vars (or using pydevd APIs). But we can always plumb that API through debugpy as needed.
Thanks, where does the justMyCode flag actually come in, is it implemented using those flags?
In case it's helpful to others until this is addressed, I've been able to workaround the issue effectively using IDE_PROJECT_ROOTS as suggested but would note one needs to add the appropriate ipykernel temp files directory (/tmp by default on Linux) in addition to the third party library code in IDE_PROJECT_ROOTS, e.g.:
IDE_PROJECT_ROOTS=/tmp:/opt/miniconda/envs/<myenv>/lib/<python_ver>/site-packages/<target third party lib>
otherwise, the 3rd-party breakpoints will work but the other breakpoints you set in your notebook will stop working. Hope this helps!
Ok. After about 20 hours of trying, I got vscode to step into to dependent python libraries during debugging. I'm running Jupyter works too.
You have to use 'base' python interpreters - NOT python environments in vscode, and set 'justmycode' to false in vscode's launch.json.
My dependent library modules are in a subdirectory of the directory that contains my Jupyter notebook and is the first directory listed when I run 'os.sys.path'
Hope this helps!
I suppose what jhcsjcao mentions leads to the solution. For me that would probably leave me with fixing the directory list produced by os.sys.path: ['\\rock64n2.lan\kbfifi\jupyter', 'd:\Users\kbfifi\anaconda3\python39.zip', 'd:\Users\kbfifi\anaconda3\DLLs', 'd:\Users\kbfifi\anaconda3\lib', 'd:\Users\kbfifi\anaconda3', '', 'd:\Users\kbfifi\anaconda3\lib\site-packages', 'd:\Users\kbfifi\anaconda3\lib\site-packages\locket-0.2.1-py3.9.egg', 'd:\Users\kbfifi\anaconda3\lib\site-packages\win32', 'd:\Users\kbfifi\anaconda3\lib\site-packages\win32\lib', 'd:\Users\kbfifi\anaconda3\lib\site-packages\Pythonwin', 'd:\Users\kbfifi\anaconda3\lib\site-packages\IPython\extensions', 'C:\Users\kbfifi\.ipython', 'C:\Users\kbfifi\AppData\Roaming\Python\Python39\site-packages']
It doesn't look really wrong to me
Although Jupyter setting "Debug just my code" set to false I get
Frame skipped from debugging during step-in. Note: may have been skipped because of "justMyCode" option (default == true). Try setting "justMyCode": false in the debug configuration (e.g., launch.json).
What am I missing?
As stated here: https://github.com/microsoft/vscode-jupyter/issues/8146#issuecomment-958443000
Just my code is not supported for stepping into cells. You have to set the environment variables like @int19h mentioned.
The real fix here would be having: https://github.com/microsoft/debugpy/issues/869 (that way we'd be able to make a distinction when library code is called because of ipython or not).
@rchiodo Thanks for the hint. I tried with from a DOS prompt: ` set IDE_PROJECT_ROOTS="c:\tmp\JupyterNotebookTmp:d:\Users\kbfifi\anaconda3\python39.zip:d:\Users\kbfifi\anaconda3\DLLs:d:\Users\kbfifi\anaconda3\lib:d:\Users\kbfifi\anaconda3:d:\Users\kbfifi\anaconda3\lib\site-packages:d:\Users\kbfifi\anaconda3\lib\site-packages\locket-0.2.1-py3.9.egg:d:\Users\kbfifi\anaconda3\lib\site-packages\win32:d:\Users\kbfifi\anaconda3\lib\site-packages\win32\lib:d:\Users\kbfifi\anaconda3\lib\site-packages\Pythonwin:d:\Users\kbfifi\anaconda3\lib\site-packages\IPython\extensions:C:\Users\kbfifi.ipython:C:\Users\kbfifi\AppData\Roaming\Python\Python39\site-packages"
code ` No luck. @speediedan what would by the Windows for /tmp as mentioned earlier in the thread: "appropriate ipykernel temp files directory (/tmp by default on Linux) "
@kbfifi the separator on Windows must be ;
instead of :
.
@faboiz thanks for noting that. Unfortunately it wasn't enough to get the workaround working. What might still help is what speediedan mentions. Do you know what the Windows path is for /tmp in Linux?
Using IDE_PROJECT_ROOTS does seem to have effect although not the wished one: Before starting to debug a cell, the breakpoint on the left of the code line is a filled red bullet. During execution the bullet becomes a grey circle which seems invalid/disabled? Any ideas?
@DonJayamanne @roblourens this issue doesn't seem to be fixed (the part related to debugpy
is now done so that stepping should work in this scenario, but there's still work to be done so that users can actually configure the justMyCode
setting in the vscode-jupyter side).
I would love a fix for this issue.
Resolution for this issue would be very helpful
As a note, a workaround while a proper UI is actually done would be changing the code locally to enable it...
This can be done as a 1-line change in the method:
pydevd.PyDB.set_use_libraries_filter
To find the proper place you can run (under the debugger):
import pydevd
print(pydevd.__file__)
Then open the related file, search the method set_use_libraries_filter
(i.e.: https://github.com/microsoft/debugpy/blob/v1.6.3/src/debugpy/_vendored/pydevd/pydevd.py#L1359)
And then locally change the variable use_libraries_filter
to the value you want (if you want justMyCode:false
, set use_libraries_filter=False
as the first thing in that method so that the parameter value is overridden to the value you want).
Oh, and also an environment variable PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING=1
must be set (or you can manually edit the value in _pydevd_bundle/pydevd_constants.py
based on the current pydevd.py
folder if setting the environment variable prior to importing the debugger is hard in the use case).
As a note, a workaround while a proper UI is actually done would be changing the code locally to enable it...
This can be done as a 1-line change in the method:
pydevd.PyDB.set_use_libraries_filter
To find the proper place you can run (under the debugger):
import pydevd print(pydevd.__file__)
Then open the related file, search the method
set_use_libraries_filter
(i.e.: https://github.com/microsoft/debugpy/blob/v1.6.3/src/debugpy/_vendored/pydevd/pydevd.py#L1359)And then locally change the variable
use_libraries_filter
to the value you want (if you wantjustMyCode:false
, setuse_libraries_filter=False
as the first thing in that method so that the parameter value is overridden to the value you want).Oh, and also an environment variable
PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING=1
must be set (or you can manually edit the value inpydevd_constants.py
which is right next topydevd.py
too if setting the environment variable prior to importing the debugger is hard in the use case).
I confirm this works with Windows 10, WSL2 Ubuntu 22.04, VSCode v1.71.1, python 3.10.4, python extension v2022.14.0. @fabioz you saved my day :')
manually edit the value in
pydevd_constants.py
which is right next topydevd.py
I got it working under macOS 12.6, Python 3.9.14 too, but I found the constants file at pydevd/_pydevd_bundle/pydevd_constants.py
instead of the mentioned pydevd/pydevd_constants.py
(in case it helps someone else). Many thanks!
I got it working under macOS 12.6, Python 3.9.14 too, but I found the constants file at
pydevd/_pydevd_bundle/pydevd_constants.py
instead of the mentionedpydevd/pydevd_constants.py
(in case it helps someone else). Many thanks!
Thanks for the note. I've updated the original comment to point the proper location.
Hey @fabioz, wondering whether you can give some guidance on what I need to adopt this? We are already setting the environment var, and if I send justMyCode:false, it works to step into library code, but I also keep stepping back out to interactiveshell.py after each line when stepping through the cell code.

That seems to be a result of what you say about ipython creating a frame for each line, in https://github.com/microsoft/debugpy/issues/869. What do I need to do to avoid this?
@roblourens I'm not sure, setting PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING=1
along with justMyCode
: false
should suffice. If it's still getting to interactiveshell.py
after each line with those changes I probably need to investigate on the debugger side (as the setting related to PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING
is done specifically to overcome that issue).
Can you also provide the version of ipython
/ipykernel
you're using? (so that I check using the same versions you're testing there...).
debugpy: 1.6.3 ipykernel: 6.15.2 ipython: 8.5.0
Am happy to help out with debugging as well if you tell me where I need to look.
I double-checked that we are setting the environment variable, by executing some code it seems, but I also see this in the debugpy log:
0.00s - Using PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING: False
does that mean that we set the env var too late, or will debugpy pick it up later?
If you do a step-over, does it work (i.e.: does that happen only on a step-in)?
i.e.:
When I do a step in in the example above it does have some weird behavior that in stops more than once in the same place before going to the next line, but I haven't managed to get to the interactiveshell.py
.
Yeah, it happens on step over. Did you modify the extension to use justMyCode=false? Note that it currently is ignoring the setting for cell debugging (but respecting it for IW debugging, actually)
I double-checked that we are setting the environment variable, by executing some code it seems, but I also see this in the debugpy log:
0.00s - Using PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING: False
does that mean that we set the env var too late, or will debugpy pick it up later?
Ok, that explains it... well, pydevd
gets that flag when it's imported, but if you just import debugpy
it won't import pydevd
right away (it only does that afterwards when some internal API is used).
You can force pydevd
to be imported with something as:
import debugpy._vendored.force_pydevd
(but if it's set after pydevd
is imported, then it's being set too late).
Yeah, it happens on step over. Did you modify the extension to use justMyCode=false? Note that it currently is ignoring the setting for cell debugging (but respecting it for IW debugging, actually)
I did that following the steps in https://github.com/microsoft/vscode-jupyter/issues/8146#issuecomment-1235731548 (i.e.: which is mostly the same as justMyCode=false
, but using internal pydevd
apis).
As a note, it seems that ipykernel
itself imports debugpy
:
https://github.com/ipython/ipykernel/blob/main/ipykernel/debugger.py#L22
I think that ipykernel
itself should set that environment variable when it's about to import debugpy
/ pydevd
.
This also means that if you import ipykernel
itself and then execute a command it's already too late (the shell that's used to start it should be configured prior to that).