vscode-jupyter icon indicating copy to clipboard operation
vscode-jupyter copied to clipboard

"Debug cell" not working in Jupyter notebooks when typings module is installed

Open garrofederico opened this issue 1 year ago • 22 comments

Environment data

  • VS Code version: Visual Studio Code (1.76.0, undefined, desktop)
  • Jupyter Extension version (available under the Extensions sidebar): 2023.2.1200692131.
  • Python Extension version (available under the Extensions sidebar): 2023.4.1.
  • OS (Windows | Mac | Linux distro) and version: MacOS Monterey 12.5.1 (21G83)
  • Python and/or Anaconda version: 3.9.10
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Jupyter server running: Local

Expected behaviour

Debug cell and the debugger should be working properly on Jupyter notebooks

Actual behaviour

At first, the option is available, but when I click on it, the debugger fires up but does nothing and the debug cell button disappears.

before:

image

after clicking on debug cell:

Screenshot 2023-03-22 at 11 45 29

and I get this error too when relaunching: image

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Just open any local Jupyter notebook and try to debug any cell

Logs

jupyter_console_output.log jupyter_console_output_2.log

garrofederico avatar Mar 22 '23 11:03 garrofederico

Any updates on the issue? Many thanks!

garrofederico avatar Mar 29 '23 10:03 garrofederico

I don't have exactly this issue. I can't debug as it constantly says "Ipykernel setup required for this feature" even though I'm sure that my ipykernels are installed.

(py39) C:\Users\username>jupyter kernelspec list Available kernels: python3 C:\Users\username.conda\envs\py39\share\jupyter\kernels\python3

as well as for base

(base) C:\Users\username>jupyter kernelspec list Unable to load extension: pydevd_plugins.extensions.types.pydevd_plugin_pandas_types Available kernels: python3 C:\ProgramData\Miniconda3\share\jupyter\kernels\python3

I wonder if this is connected?

fschiffers avatar Mar 29 '23 20:03 fschiffers

@fschiffers please could you file a seprate issue as it looks unrelated, that way we can look at both individually. @garrofederico Sorry for not getting back, please could you try installing VS Code insiders and letting me know if this still exists in the latest pre-releaes version of jupyter extension and pre-release version of the Python extensoin

  • Please install latest VS Code Insiders
  • Open the extensions page, search for Jupyter and click the button Switch to Pre-Release Version
  • Similarly please install the latest Pre-Release version of the Python extension
Screenshot 2023-02-04 at 09 24 37

DonJayamanne avatar Mar 29 '23 21:03 DonJayamanne

@DonJayamanne , Thanks for your response.

  • I installed the latest VS Code Insiders

  • I installed the latest pre-release of the Python extension

  • However, I wasn't able to switch to the Pre-Release Version of the Jupyter extension, this option is not available to me in VS Code insiders nor Stable version: image

Anyway, I tested debbuging on the Insiders version and it is still not working.

garrofederico avatar Mar 30 '23 11:03 garrofederico

Hi @garrofederico, maybe it's just that you need to add the breakpoint before starting Debug Cell? I see it in the second screenshot but not the first, so it's not clear if it was there before you started.

If that doesn't help, can you set the setting "jupyter.logging.level": "verbose", try again, and grab the log again? Thanks

roblourens avatar Mar 30 '23 19:03 roblourens

Hi @roblourens, thanks for helping out. Here's a screen shot that shows everything at once: image

I tested it again (with the breakpoints, of course) and it is not working. Here's the log as you asked: jupyter_console_output_3.log

garrofederico avatar Mar 31 '23 10:03 garrofederico

Yeah, something is going on, it's getting stuck when we start the debugger but I'm not sure why. I can tell you that the restart button will not work currently and will give you that error message though.

roblourens avatar Mar 31 '23 17:03 roblourens

Hi, is there any update on this matter? Thanks!

garrofederico avatar Apr 19 '23 07:04 garrofederico

An update: the debugger is working correctly on jupyter notebooks when I'm connected to a remote server.

Is there any update on your side?

garrofederico avatar Apr 26 '23 12:04 garrofederico

I have the same issue. I realized when i import models from super_gradients.training, "Ipykernel setup required for this feature" occurs. otherwise the debug feature works well.

SzaremehrjardiMT avatar May 09 '23 15:05 SzaremehrjardiMT

Having the same problem on my Windows Machine:

  • VS Code Version: 1.78.2
  • OS: Windows 11
  • Python Version: 3.10.8
  • Jupyter Extension Version: 2023.4.1011241018
  • Python Extension Version: 2023.8.0

variolam avatar May 16 '23 10:05 variolam

I get this every time I want to debug some cell

image

And that's it, breakpoints aren't reached, debugger shows nothing, even the play button stops showing the little arrow at the side image

memeplex avatar Jun 14 '23 19:06 memeplex

@memeplex I am experiencing the exact same problem.

  • VS Code version: Version: 1.79.0 (Universal) Commit: b380da4ef1ee00e224a15c1d4d9793e27c2b6302 Date: 2023-06-07T14:29:00.206Z (1 wk ago) Electron: 22.5.5 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Darwin arm64 22.4.0
  • Jupyter Extension version (available under the Extensions sidebar): v2023.5.1001582324
  • Python Extension version (available under the Extensions sidebar): v2023.10.1
  • OS (Windows | Mac | Linux distro) and version: Local: Ventura Version 13.3.1 (a) (22E772610a)
  • Python and/or Anaconda version: 3.10.11 (Python version)
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Jupyter server running: Remote (sshing)

sarvghotra avatar Jun 19 '23 01:06 sarvghotra

I am also having same issue on y system

Version: 1.79.2 (user setup) Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06 Date: 2023-06-14T08:57:04.379Z Electron: 22.5.7 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.22621

Jupyter v2023.5.1101742258

Able to execute cell but I am unable to see Debug cell option in visual studio code

raiajithkumarr avatar Jul 05 '23 08:07 raiajithkumarr

I was able to work around the issue by creating a new virtual environment.

LHLaurini avatar Jul 20 '23 16:07 LHLaurini

I think I found the root cause for this error, at least for my case:

If you create a virtual environment using virtualenv and you rename or change ANY part of the path where the virtual environment is located, your interpreter will be broken. You won't see any error messages, except in some specific use-cases.

In my case I only found this error while trying to login using huggingface-cli and the command was not found although the transformers package was installed correctly and working otherwise. Therefore, I executed the command directly via its installation location .venv/bin/huggingface-cli and got the following error:

zsh: .venv/bin/huggingface-cli: bad interpreter: /home/some-user/projects/.venv/bin/python: no such file or directory

That's where I saw the missing folder in the path.

As mentioned by @LHLaurini the solution would be to delete the environment and create a new one or change the paths back how they where while installing the environment.

variolam avatar Aug 09 '23 12:08 variolam

I've been able to reliably reproduce the bug in the following scenario: setup virtual environment: virtualenv venv test the debugger -> still works pip install typing test the debugger -> still works restart the kernel test the debugger -> now I get the error image

I still don't understand the issue, but I found that the debugger works if I use conda to make a virtual environment and to install the typing package.

To emphasize, I can pip install any package, or conda install typing. The error only comes up when I "pip install typing" and I restart the kernel.

celistimen avatar Aug 14 '23 09:08 celistimen

Met with the same issue.

lwhere avatar Oct 09 '23 07:10 lwhere

same issue for me

stw-ableton avatar Dec 12 '23 14:12 stw-ableton

Suggestion

When debugging, warn users if typings module is installed

DonJayamanne avatar Dec 13 '23 01:12 DonJayamanne

The debug cell in Edge disappeared, but it works normally in Chrome

image

moyueheng avatar Mar 20 '24 09:03 moyueheng

Successfully fixed debugging in Jupyter notebook in VSCode

Summarizing the findings of all related threads in a single post to help the many others wasting time debugging this.

:x: Before: Error ✅ After: Working!
image image

Diagnosing the Problem

First, look at the Jupyter extension logs:

image

Unfortunately, you may only receive this as the last log message:

16:56:43.944 [info] Starting debugging with mode 1

This is not helpful.

If so, then next step is change VSCode settings:

jupyter.logging.level": "verbose"

Then run VSCode command Developer: Reload Window.

Now you should receive the error message. For example, in my case I had the same error message as https://github.com/microsoft/vscode-jupyter/issues/15562#issuecomment-2062746960 from typing and debugpy:

...
16:56:43.988 [debug] [Debug] to kernel, mapped: {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"Python Kernel Debug Adapter","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en","supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryReferences":true,"supportsArgsCanBeInterpretedByShell":true,"supportsMemoryEvent":true,"supportsStartDebuggingRequest":true},"type":"request","seq":1}
16:56:44.013 [debug] KernelProcess error 11981: Traceback (most recent call last):
  File "/opt/miniconda3/envs/pytorch/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/miniconda3/envs/pytorch/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/opt/miniconda3/envs/pytorch/lib/python3.8/site-packages/debugpy/adapter/__main__.py", line 215, in <module>
    __import__("debugpy")
  File "/opt/miniconda3/envs/pytorch/lib/python3.8/site-packages/debugpy/adapter/../../debugpy/__init__.py", line 35, in <module>
    from debugpy.public_api import *  # noqa
  File "/opt/miniconda3/envs/pytorch/lib/python3.8/site-packages/debugpy/adapter/../../debugpy/public_api.py", line 8, in <module>
    import typing
  File "/opt/miniconda3/envs/pytorch/lib/python3.8/site-packages/debugpy/adapter/../../typing.py", line 1359, in <module>
    class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
  File "/opt/miniconda3/envs/pytorch/lib/python3.8/site-packages/debugpy/adapter/../../typing.py", line 1007, in __new__
    self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'

16:56:54.185 [debug] [Debug] response: {"command":"initialize","request_seq":1,"seq":3,"success":false,"type":"response"}
...

Solution

As stated above, the solution is to uninstall typing module/package:

pip uninstall typing

Explanation

I didn't fully understand why until found this explanation from https://stackoverflow.com/questions/55833509/attributeerror-type-object-callable-has-no-attribute-abc-registry#comment113222151_58067012

The typing package is only relevant on Python <= 3.5. Later versions include the typing module built-in, so you should uninstall it anyway. – WhyNotHugo

For Python versions:

  • <3.5: typing library, https://pypi.org/project/typing/
  • >=3.5: Built-in, https://docs.python.org/3/library/typing.html

Hope this helps anyone else quickly come to a resolution and understanding!

Glavin001 avatar Jul 07 '24 00:07 Glavin001