Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using %matplotlib widget results in `KeyError: 'modifiers'. #12888

Closed
raaaaaymond opened this issue Feb 21, 2023 · 9 comments
Closed

Using %matplotlib widget results in `KeyError: 'modifiers'. #12888

raaaaaymond opened this issue Feb 21, 2023 · 9 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug user-setup Issues caused by incorrectly configured python environments, packages, or the like

Comments

@raaaaaymond
Copy link

Environment data

  • VS Code version:
Version: 1.75.1 (user setup)
Commit: 441438abd1ac652551dbe4d408dfcec8a499b8bf
Date: 2023-02-08T21:32:34.589Z
Electron: 19.1.9
Chromium: 102.0.5005.194
Node.js: 16.14.2
V8: 10.2.154.23-electron.0
OS: Windows_NT x64 10.0.22621
Sandboxed: No
  • Jupyter Extension version (available under the Extensions sidebar): v2023.1.2010391206
  • Python Extension version (available under the Extensions sidebar): v2023.2.0
  • OS (Windows | Mac | Linux distro) and version: Windows 11
  • Python and/or Anaconda version: 3.10.1
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Jupyter server running: Local

Expected behaviour

No errors.

Actual behaviour

The figure shows correctly but there are repeated KeyError: 'modifiers' that makes the output cell extremely long. See screen shot This error does not show when I'm using Jupyter Notebook in my browser (started from the command line), but only in VSCode. Note that the errors appear seconds or sometimes minutes after the figure is shown correctly. In order to reproduce, you must wait a good few seconds after running the code.

JupyterMatplotlibError

Steps to reproduce:

Paste the following code into a cell in a new .ipynb file and run. Note that the errors appear seconds or sometimes minutes after the figure is shown correctly. In order to reproduce, you must wait a good few seconds after running the code in order to see the errors.

%matplotlib widget

import numpy as np
import matplotlib.pyplot as plt

generator = np.random.default_rng()

_, axes = plt.subplots()
random = generator.uniform(0, 1, (1390,))
axes.plot(random)

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

Visual Studio Code (1.75.1, undefined, desktop)
Jupyter Extension Version: 2023.1.2010391206.
Python Extension Version: 2023.2.0.
Workspace folder c:\Users\raaaa\Dev\research
User belongs to experiment group 'jupyterTest'
User belongs to experiment group 'jupyterEnhancedDataViewer'
info 12:22:12.182: LSP Notebooks experiment is enabled
info 12:22:12.596: Find preferred kernel for c:\Users\raaaa\Dev\research\src\python\wtf.ipynb with metadata {"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.1"},"orig_nbformat":4,"vscode":{"interpreter":{"hash":"377ed70cde78874502efeb95ea33073c14a19ade0c532bba2731dee70c0c0238"}}} & preferred interpreter c:\Users\raaaa\AppData\Local\Programs\Python\Python310\python.exe
info 12:22:12.599: Preferred kernel .jvsc74a57bd0377ed70cde78874502efeb95ea33073c14a19ade0c532bba2731dee70c0c0238.c:\Users\raaaa\AppData\Local\Programs\Python\Python310\python.exe.c:\Users\raaaa\AppData\Local\Programs\Python\Python310\python.exe.-m#ipykernel_launcher is exact match or top match for non python kernels, (true, [object Object], true, false)
info 12:22:12.599: PreferredConnection: .jvsc74a57bd0377ed70cde78874502efeb95ea33073c14a19ade0c532bba2731dee70c0c0238.c:\Users\raaaa\AppData\Local\Programs\Python\Python310\python.exe.c:\Users\raaaa\AppData\Local\Programs\Python\Python310\python.exe.-m#ipykernel_launcher found for NotebookDocument: c:\Users\raaaa\Dev\research\src\python\wtf.ipynb
info 12:22:13.024: Process Execution: > ~\AppData\Local\Programs\Python\Python310\python.exe -m pip list
> ~\AppData\Local\Programs\Python\Python310\python.exe -m pip list
info 12:23:09.096: Starting Jupyter Session startUsingPythonInterpreter, .jvsc74a57bd0377ed70cde78874502efeb95ea33073c14a19ade0c532bba2731dee70c0c0238.c:\Users\raaaa\AppData\Local\Programs\Python\Python310\python.exe.c:\Users\raaaa\AppData\Local\Programs\Python\Python310\python.exe.-m#ipykernel_launcher (Python Path: , EnvType: Unknown, EnvName: '', Version: 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]) for 'c:\Users\raaaa\Dev\research\src\python\wtf.ipynb' (disableUI=false)
info 12:23:09.166: Process Execution: > ~\AppData\Local\Programs\Python\Python310\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
> ~\AppData\Local\Programs\Python\Python310\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
info 12:23:09.196: Process Execution: > ~\AppData\Local\Programs\Python\Python310\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2023.1.2010391206\pythonFiles\vscode_datascience_helpers\kernel_interrupt_daemon.py --ppid 12504
> ~\AppData\Local\Programs\Python\Python310\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2023.1.2010391206\pythonFiles\vscode_datascience_helpers\kernel_interrupt_daemon.py --ppid 12504
info 12:23:09.196: Process Execution: cwd: ~\.vscode\extensions\ms-toolsai.jupyter-2023.1.2010391206\pythonFiles\vscode_datascience_helpers
cwd: ~\.vscode\extensions\ms-toolsai.jupyter-2023.1.2010391206\pythonFiles\vscode_datascience_helpers
info 12:23:09.311: Process Execution: > ~\AppData\Local\Programs\Python\Python310\python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"b650c331-1d7c-4e43-b0ae-d05b32ba4f52" --shell=9002 --transport="tcp" --iopub=9004 --f=c:\Users\raaaa\AppData\Roaming\jupyter\runtime\kernel-v2-12504BotWhtyFiBp9.json
> ~\AppData\Local\Programs\Python\Python310\python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"b650c331-1d7c-4e43-b0ae-d05b32ba4f52" --shell=9002 --transport="tcp" --iopub=9004 --f=c:\Users\raaaa\AppData\Roaming\jupyter\runtime\kernel-v2-12504BotWhtyFiBp9.json
info 12:23:09.311: Process Execution: cwd: ~\Dev\research\src\python
cwd: ~\Dev\research\src\python
info 12:23:09.496: ipykernel version & path 6.21.2, ~\AppData\Local\Programs\Python\Python310\lib\site-packages\ipykernel\__init__.py for c:\Users\raaaa\AppData\Local\Programs\Python\Python310\python.exe
info 12:23:10.578: Started Kernel Python 3.10.1 (pid: 14092)
info 12:23:10.655: Process Execution: > ~\AppData\Local\Programs\Python\Python310\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2023.1.2010391206\pythonFiles\printJupyterDataDir.py
> ~\AppData\Local\Programs\Python\Python310\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2023.1.2010391206\pythonFiles\printJupyterDataDir.py
info 12:23:11.574: �[32mFetch Script for {"moduleName":"jupyter-matplotlib","moduleVersion":"^0.11","requestId":"jupyter-matplotlib:^0.11:1676982191573"}
info 12:23:11.574: �[32mFetch Script for jupyter-matplotlib
info 12:23:11.574: �[32mSearching for Widget Script jupyter-matplotlib#^0.11 using cdns jsdelivr.com unpkg.com
info 12:23:11.729: �[32mWidget Script jupyter-matplotlib#^0.11 found at URI: https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js
info 12:23:11.729: Script source for Widget jupyter-matplotlib@^0.11 was found from source cdn
info 12:23:11.729: �[32mScript for jupyter-matplotlib, is https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js from cdn
info 12:23:11.872: �[32mFetch Script for jupyter-matplotlib
info 12:23:11.872: Script source for Widget jupyter-matplotlib@^0.11 was found from source cdn
info 12:23:11.872: �[32mScript for jupyter-matplotlib, is https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js from cdn

@raaaaaymond raaaaaymond added the bug Issue identified by VS Code Team member as probable bug label Feb 21, 2023
@christasich
Copy link

I ran into this issue earlier. It's likely due to an incompatibility between your versions of matplotlib and ipympl. It's caused by matplotlib/matplotlib#23473 and fixed in matplotlib/ipympl#517. Upgrading to ipympl==0.9.3 fixed the issue for me.

@DonJayamanne
Copy link
Contributor

I believe this is caused by an environment issue (issue with packages at your end)
Please try what was suggested by @christasich
If that does not work, please try the following

  • 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

Closing for now, if the issue persists, please do feel free to ping here and i'll re-open this issue or feel free to re-open your self or create a new issue and i'll look into this.

@josephzsombor
Copy link

josephzsombor commented May 7, 2023

I'm still having this issue and I've upgraded VSCode, ipympl, etc.
ipympl 0.9.3, matplotlib 3.7.1, jupyterlab 3.6.3

@CYHSM
Copy link

CYHSM commented May 9, 2023

Had the same issue, switching to pre-release versions of Jupyter and Python fixed it (as mentioned above)

@josephzsombor
Copy link

I get "Can't install pre-release version of 'ms-toolsai.jupyter' extension because it is not compatible with the current version of Visual Studio Code (version 1.78.0)."
I believe 1.78.0 is the latest version of VS Code, so I'd kinda prefer not to downgrade.

@hhnam96
Copy link

hhnam96 commented May 30, 2023

I get "Can't install pre-release version of 'ms-toolsai.jupyter' extension because it is not compatible with the current version of Visual Studio Code (version 1.78.0)." I believe 1.78.0 is the latest version of VS Code, so I'd kinda prefer not to downgrade.
Had the same issue.

@giladpn
Copy link

giladpn commented Jun 2, 2023

I ran into this issue earlier. It's likely due to an incompatibility between your versions of matplotlib and ipympl. It's caused by matplotlib/matplotlib#23473 and fixed in matplotlib/ipympl#517. Upgrading to ipympl==0.9.3 fixed the issue for me.

An addition to the above advice.

This solution now does work, at least with my combination of vscode 1.78.2, python 3.10.6, python vscode extension 2023.8.0, matplotlib 3.7.1 and ipympl 0.9.3.

But, I had to restart vscode (twice!) after upgrading to the above, before it "settled down". Just FYI.

@DonJayamanne DonJayamanne added the user-setup Issues caused by incorrectly configured python environments, packages, or the like label Jun 2, 2023
@shyel-cohen
Copy link

This solution now does work, at least with my combination of vscode 1.78.2, python 3.10.6, python vscode extension 2023.8.0, matplotlib 3.7.1 and ipympl 0.9.3.

I have tried that combination of versions with the exception of python 3.8.13 and I am getting the above exception when the mouse hovers over the plot, while not getting the exception when using the browser.

Currently downgraded matplotlib and it is working as expected.

@ChristofKaufmann
Copy link

I tried upgrading related packages (jupyter*, ipy*, matplotlib), but it did not help. Upgrading the complete environment (mamba update --all) (and restarting VS Code) worked.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug user-setup Issues caused by incorrectly configured python environments, packages, or the like
Projects
None yet
Development

No branches or pull requests

10 participants