matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.56k stars 226 forks source link

%matplotlib widget run time error #559

Open PaolaGith opened 1 month ago

PaolaGith commented 1 month ago

Hello, I saw an old issue about this topic, but I could not find a recent solution. I am using a Linux machine, Python version 3.12.4. I created my environment and I installed matplotlib by using pip install matplotlib

But when I run my code in VS code, I get a runtime error related to %matplotlib widget

RuntimeError Traceback (most recent call last) File ~/.conda/envs/s_i/lib/python3.12/site-packages/matplotlib/backends/registry.py:413, in BackendRegistry.resolve_gui_or_backend(self, gui_or_backend) 412 try: --> 413 return self.resolve_backend(gui_or_backend) 414 except Exception: # KeyError ?

File ~/.conda/envs/s_i/lib/python3.12/site-packages/matplotlib/backends/registry.py:375, in BackendRegistry.resolve_backend(self, backend) 374 if gui is None: --> 375 raise RuntimeError(f"'{backend}' is not a recognised backend name") 377 return backend, gui if gui != "headless" else None

RuntimeError: 'widget' is not a recognised backend name

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last) Cell In[3], line 8 3 from pathlib import Path 5 #import ephyviewer 6 #import spikeinterface_gui as sigui ----> 8 get_ipython().run_line_magic('matplotlib', 'widget') 9 get_ipython().run_line_magic('matplotlib', 'inline') 10 #%matplotlib notebook ... 414 except Exception: # KeyError ? --> 415 raise RuntimeError( 416 f"'{gui_or_backend} is not a recognised GUI loop or backend name")

RuntimeError: 'widget is not a recognised GUI loop or backend name

Have you found a solution for this issue? thank you

ianthomas23 commented 1 month ago

Please can you tell us what versions of packages you have installed by running pip list?

PaolaGith commented 1 month ago

Sure,

Package Version Editable project location


aiobotocore 2.7.0 aiohttp 3.9.3 aioitertools 0.7.1 aiosignal 1.2.0 alabaster 0.7.12 altair 5.0.1 anaconda-anon-usage 0.4.3 anaconda-catalogs 0.2.0 anaconda-client 1.12.3 anaconda-cloud-auth 0.1.4 anaconda-navigator 2.5.2 anaconda-project 0.11.1 anyio 4.2.0 appdirs 1.4.4 archspec 0.2.1 argon2-cffi 21.3.0 argon2-cffi-bindings 21.2.0 arrow 1.2.3 asciitree 0.3.3 astroid 2.14.2 astropy 5.3.4 asttokens 2.0.5 async-lru 2.0.4 atomicwrites 1.4.0 attrs 23.1.0 Automat 20.2.0 autopep8 1.6.0 Babel 2.11.0 backports.functools-lru-cache 1.6.4 backports.tempfile 1.0 backports.weakref 1.0.post1 bcrypt 3.2.0 beautifulsoup4 4.12.2 binaryornot 0.4.4 black 23.11.0 bleach 4.1.0 blinker 1.6.2 bokeh 3.3.4 boltons 23.0.0 botocore 1.31.64 Bottleneck 1.3.7 Brotli 1.0.9 cachetools 4.2.2 cbor2 5.6.4 certifi 2024.2.2 cffi 1.16.0 chardet 4.0.0 charset-normalizer 2.0.4 click 8.1.7 cloudpickle 2.2.1 clyent 1.2.2 colorama 0.4.6 colorcet 3.0.1 comm 0.1.2 conda 24.1.2 conda-build 24.1.2 conda-content-trust 0.2.0 conda_index 0.4.0 conda-libmamba-solver 24.1.0 conda-pack 0.6.0 conda-package-handling 2.2.0 conda_package_streaming 0.9.0 conda-repo-cli 1.0.75 conda-token 0.4.0 conda-verify 3.4.2 constantly 23.10.4 contourpy 1.2.0 cookiecutter 2.5.0 cryptography 42.0.2 cssselect 1.2.0 cuda-python 12.5.0 cycler 0.11.0 cytoolz 0.12.2 dask 2023.11.0 datashader 0.16.0 debugpy 1.6.7 decorator 5.1.1 defusedxml 0.7.1 diff-match-patch 20200713 dill 0.3.7 distinctipy 1.3.4 distributed 2023.11.0 distro 1.8.0 docstring-to-markdown 0.11 docutils 0.18.1 entrypoints 0.4 et-xmlfile 1.1.0 executing 0.8.3 fasteners 0.19 fastjsonschema 2.16.2 figurl 0.2.22 filelock 3.13.1 flake8 6.0.0 Flask 2.2.5 fonttools 4.25.0 fqdn 1.5.1 frozenlist 1.4.0 fsspec 2023.10.0 future 0.18.3 gensim 4.3.0 gitdb 4.0.7 GitPython 3.1.37 gmpy2 2.1.2 greenlet 3.0.1 h5py 3.9.0 hdmf 3.14.2 HeapDict 1.0.1 holoviews 1.18.3 hvplot 0.9.2 hyperlink 21.0.0 idna 3.4 imagecodecs 2023.1.23 imageio 2.33.1 imagesize 1.4.1 imbalanced-learn 0.11.0 importlib-metadata 7.0.1 incremental 22.10.0 inflection 0.5.1 iniconfig 1.1.1 intake 0.6.8 intervaltree 3.1.0 ipykernel 6.28.0 ipympl 0.9.4 ipython 8.20.0 ipython-genutils 0.2.0 ipywidgets 7.6.5 isoduration 20.11.0 isort 5.9.3 isosplit6 0.1.4 itemadapter 0.3.0 itemloaders 1.1.0 itsdangerous 2.0.1 jaraco.classes 3.2.1 jedi 0.18.1 jeepney 0.7.1 jellyfish 1.0.1 Jinja2 3.1.3 jmespath 1.0.1 joblib 1.2.0 json5 0.9.6 jsonpatch 1.32 jsonpointer 2.1 jsonschema 4.19.2 jsonschema-specifications 2023.7.1 jupyter 1.0.0 jupyter_client 8.6.0 jupyter-console 6.6.3 jupyter_core 5.5.0 jupyter-events 0.8.0 jupyter-lsp 2.2.0 jupyter_server 2.10.0 jupyter_server_terminals 0.4.4 jupyterlab 4.0.11 jupyterlab-pygments 0.1.2 jupyterlab_server 2.25.1 jupyterlab-widgets 3.0.9 kachery-cloud 0.4.9 keyring 23.13.1 kiwisolver 1.4.4 lazy_loader 0.3 lazy-object-proxy 1.6.0 lckr_jupyterlab_variableinspector 3.1.0 libarchive-c 2.9 libmambapy 1.5.6 linkify-it-py 2.0.0 llvmlite 0.42.0 lmdb 1.4.1 locket 1.0.0 lxml 4.9.3 lz4 4.3.2 Markdown 3.4.1 markdown-it-py 2.2.0 MarkupSafe 2.1.3 matplotlib 3.8.0 matplotlib-inline 0.1.6 mccabe 0.7.0 mdit-py-plugins 0.3.0 mdurl 0.1.0 menuinst 2.0.2 mistune 2.0.4 mkl-fft 1.3.8 mkl-random 1.2.4 mkl-service 2.4.0 more-itertools 10.1.0 mountainsort5 0.5.6 mpmath 1.3.0 msgpack 1.0.3 multidict 6.0.4 multipledispatch 0.6.0 munkres 1.1.4 mypy 1.8.0 mypy-extensions 1.0.0 navigator-updater 0.4.0 nbclient 0.8.0 nbconvert 7.10.0 nbformat 5.9.2 neo 0.13.1 nest-asyncio 1.6.0 networkx 3.1 nltk 3.8.1 notebook 7.0.8 notebook_shim 0.2.3 numba 0.59.0 numcodecs 0.12.1 numexpr 2.8.7 numpy 1.26.4 numpydoc 1.5.0 openpyxl 3.0.10 overrides 7.4.0 packaging 23.1 pandas 2.1.4 pandocfilters 1.5.0 panel 1.3.8 param 2.0.2 parsel 1.8.1 parso 0.8.3 partd 1.4.1 pathlib 1.0.1 pathspec 0.10.3 patsy 0.5.3 pexpect 4.8.0 pickleshare 0.7.5 pillow 10.2.0 pip 23.3.1 pkce 1.0.3 pkginfo 1.9.6 platformdirs 3.10.0 plotly 5.9.0 pluggy 1.0.0 ply 3.11 probeinterface 0.2.21 prometheus-client 0.14.1 prompt-toolkit 3.0.43 Protego 0.1.16 protobuf 3.20.3 psutil 5.9.0 ptyprocess 0.7.0 pubnub 8.0.0 pure-eval 0.2.2 py-cpuinfo 9.0.0 pyarrow 14.0.2 pyasn1 0.4.8 pyasn1-modules 0.2.8 pycodestyle 2.10.0 pycosat 0.6.6 pycparser 2.21 pycryptodomex 3.20.0 pyct 0.5.0 pycurl 7.45.2 pydantic 1.10.12 pydeck 0.8.0 PyDispatcher 2.0.5 pydocstyle 6.3.0 pyerfa 2.0.0 pyflakes 3.0.1 Pygments 2.15.1 PyJWT 2.4.0 pylint 2.16.2 pylint-venv 2.3.0 pyls-spyder 0.4.0 pynwb 2.8.1 pyodbc 5.0.1 pyOpenSSL 24.0.0 pyparsing 3.0.9 PyQt5 5.15.10 PyQt5-sip 12.13.0 PyQtWebEngine 5.15.6 PySocks 1.7.1 pytest 7.4.0 python-dateutil 2.8.2 python-dotenv 0.21.0 python-json-logger 2.0.7 python-lsp-black 1.2.1 python-lsp-jsonrpc 1.0.0 python-lsp-server 1.7.2 python-slugify 5.0.2 python-snappy 0.6.1 pytoolconfig 1.2.6 pytz 2023.3.post1 pyviz_comms 3.0.0 pywavelets 1.5.0 pyxdg 0.27 PyYAML 6.0.1 pyzmq 25.1.2 QDarkStyle 3.0.2 qstylizer 0.2.2 QtAwesome 1.2.2 qtconsole 5.4.2 QtPy 2.4.1 quantities 0.15.0 queuelib 1.6.2 referencing 0.30.2 regex 2023.10.3 requests 2.31.0 requests-file 1.5.1 requests-toolbelt 1.0.0 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 rich 13.3.5 rope 1.7.0 rpds-py 0.10.6 Rtree 1.0.1 ruamel.yaml 0.17.21 ruamel-yaml-conda 0.17.21 s3fs 2023.10.0 scikit-image 0.22.0 scikit-learn 1.2.2 scipy 1.11.4 Scrapy 2.8.0 seaborn 0.12.2 SecretStorage 3.3.1 semver 2.13.0 Send2Trash 1.8.2 service-identity 18.1.0 setuptools 68.2.2 simplejson 3.19.2 sip 6.7.12 six 1.16.0 smart-open 5.2.1 smmap 4.0.0 sniffio 1.3.0 snowballstemmer 2.2.0 sortedcontainers 2.4.0 sortingview 0.13.4 soupsieve 2.5 Sphinx 5.0.2 sphinxcontrib-applehelp 1.0.2 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.0 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.5 spikeinterface 0.101.0rc0 /home/Paola/spikeinterface spyder 5.4.3 spyder-kernels 2.4.4 SQLAlchemy 2.0.25 stack-data 0.2.0 statsmodels 0.14.0 streamlit 1.30.0 sympy 1.12 tables 3.9.2 tabulate 0.9.0 tblib 1.7.0 tenacity 8.2.2 terminado 0.17.1 text-unidecode 1.3 textdistance 4.2.1 threadpoolctl 3.5.0 three-merge 0.1.1 tifffile 2023.4.12 tinycss2 1.2.1 tldextract 3.2.0 toml 0.10.2 tomlkit 0.11.1 toolz 0.12.0 tornado 6.3.3 tqdm 4.65.0 traitlets 5.7.1 truststore 0.8.0 Twisted 23.10.0 typing_extensions 4.9.0 tzdata 2023.3 tzlocal 2.1 uc-micro-py 1.0.1 ujson 5.4.0 Unidecode 1.2.0 uri-template 1.3.0 urllib3 2.0.7 validators 0.18.2 w3lib 2.1.2 watchdog 2.1.6 wcwidth 0.2.5 webcolors 24.6.0 webencodings 0.5.1 websocket-client 0.58.0 Werkzeug 2.2.3 whatthepatch 1.0.2 wheel 0.41.2 widgetsnbextension 3.5.2 wrapt 1.14.1 wurlitzer 3.0.2 xarray 2023.6.0 xyzservices 2022.9.0 yapf 0.31.0 yarl 1.9.3 zarr 2.17.2 zict 3.0.0 zipp 3.17.0 zope.interface 5.4.0 zstandard 0.19.0

Thanks!

ianthomas23 commented 1 month ago

The runtime error is reported in the file lib/matplotlib/backends/registry.py which was added to Matplotlib in version 3.9.0. Your environment claims that it only has Matplotlib 3.8.0. So either your environment is messed up, or VSCode has some other version of Matplotlib that it is using here. Given that you are using a conda environment but you have used pip install matplotlib into it, I suspect the former. Combining conda install and pip install in the same environment can often cause problems.

To exclude VSCode as the source of the problem you could run jupyter lab or notebook from the command line using this environment and run your %matplotlib widget code in that to see what happens.

You could also run conda list and see how the output compares to your pip list.

PaolaGith commented 1 month ago

Thanks for your answer. I was able to run my code using jupyter notebook and I did not get the error for %matplotlib widget. Here is the conda list:

packages in environment at /home/Paola/.conda/envs/s_i:

#

Name Version Build Channel

_libgcc_mutex 0.1 main
_openmp_mutex 5.1 1_gnu
anyio 4.4.0 pypi_0 pypi argon2-cffi 23.1.0 pypi_0 pypi argon2-cffi-bindings 21.2.0 pypi_0 pypi arrow 1.3.0 pypi_0 pypi asciitree 0.3.3 pypi_0 pypi asttokens 2.4.1 pypi_0 pypi async-lru 2.0.4 pypi_0 pypi attrs 23.2.0 pypi_0 pypi babel 2.15.0 pypi_0 pypi beautifulsoup4 4.12.3 pypi_0 pypi bleach 6.1.0 pypi_0 pypi bzip2 1.0.8 h5eee18b_6
ca-certificates 2024.3.11 h06a4308_0
certifi 2024.7.4 pypi_0 pypi cffi 1.16.0 pypi_0 pypi charset-normalizer 3.3.2 pypi_0 pypi comm 0.2.2 pypi_0 pypi contourpy 1.2.1 pypi_0 pypi cycler 0.12.1 pypi_0 pypi debugpy 1.8.2 pypi_0 pypi decorator 5.1.1 pypi_0 pypi defusedxml 0.7.1 pypi_0 pypi executing 2.0.1 pypi_0 pypi expat 2.6.2 h6a678d5_0
fasteners 0.19 pypi_0 pypi fastjsonschema 2.20.0 pypi_0 pypi fonttools 4.53.1 pypi_0 pypi fqdn 1.5.1 pypi_0 pypi h11 0.14.0 pypi_0 pypi h5py 3.11.0 pypi_0 pypi httpcore 1.0.5 pypi_0 pypi httpx 0.27.0 pypi_0 pypi idna 3.7 pypi_0 pypi ipykernel 6.29.5 pypi_0 pypi ipympl 0.9.4 pypi_0 pypi ipython 8.26.0 pypi_0 pypi ipython-genutils 0.2.0 pypi_0 pypi ipywidgets 8.1.3 pypi_0 pypi isoduration 20.11.0 pypi_0 pypi isosplit6 0.1.4 pypi_0 pypi jedi 0.19.1 pypi_0 pypi jinja2 3.1.4 pypi_0 pypi joblib 1.4.2 pypi_0 pypi json5 0.9.25 pypi_0 pypi jsonpointer 3.0.0 pypi_0 pypi jsonschema 4.23.0 pypi_0 pypi jsonschema-specifications 2023.12.1 pypi_0 pypi jupyter-client 8.6.2 pypi_0 pypi jupyter-core 5.7.2 pypi_0 pypi jupyter-events 0.10.0 pypi_0 pypi jupyter-lsp 2.2.5 pypi_0 pypi jupyter-server 2.14.1 pypi_0 pypi jupyter-server-terminals 0.5.3 pypi_0 pypi jupyterlab 4.2.3 pypi_0 pypi jupyterlab-pygments 0.3.0 pypi_0 pypi jupyterlab-server 2.27.2 pypi_0 pypi jupyterlab-widgets 3.0.11 pypi_0 pypi kiwisolver 1.4.5 pypi_0 pypi ld_impl_linux-64 2.38 h1181459_1
libffi 3.4.4 h6a678d5_1
libgcc-ng 11.2.0 h1234567_1
libgomp 11.2.0 h1234567_1
libstdcxx-ng 11.2.0 h1234567_1
libuuid 1.41.5 h5eee18b_0
markupsafe 2.1.5 pypi_0 pypi mat73 0.63 pypi_0 pypi matplotlib 3.9.1 pypi_0 pypi matplotlib-inline 0.1.7 pypi_0 pypi mistune 3.0.2 pypi_0 pypi mountainsort5 0.5.6 pypi_0 pypi nbclient 0.10.0 pypi_0 pypi nbconvert 7.16.4 pypi_0 pypi nbformat 5.10.4 pypi_0 pypi ncurses 6.4 h6a678d5_0
neo 0.13.1 pypi_0 pypi nest-asyncio 1.6.0 pypi_0 pypi notebook 7.2.1 pypi_0 pypi notebook-shim 0.2.4 pypi_0 pypi numcodecs 0.12.1 pypi_0 pypi numpy 1.26.4 pypi_0 pypi openssl 3.0.14 h5eee18b_0
overrides 7.7.0 pypi_0 pypi packaging 24.1 pypi_0 pypi pandocfilters 1.5.1 pypi_0 pypi parso 0.8.4 pypi_0 pypi pexpect 4.9.0 pypi_0 pypi pillow 10.4.0 pypi_0 pypi pip 24.0 py312h06a4308_0
platformdirs 4.2.2 pypi_0 pypi probeinterface 0.2.21 pypi_0 pypi prometheus-client 0.20.0 pypi_0 pypi prompt-toolkit 3.0.47 pypi_0 pypi psutil 6.0.0 pypi_0 pypi ptyprocess 0.7.0 pypi_0 pypi pure-eval 0.2.2 pypi_0 pypi pycparser 2.22 pypi_0 pypi pygments 2.18.0 pypi_0 pypi pyparsing 3.1.2 pypi_0 pypi python 3.12.4 h5148396_1
python-dateutil 2.9.0.post0 pypi_0 pypi python-json-logger 2.0.7 pypi_0 pypi pyyaml 6.0.1 pypi_0 pypi pyzmq 26.0.3 pypi_0 pypi quantities 0.15.0 pypi_0 pypi readline 8.2 h5eee18b_0
referencing 0.35.1 pypi_0 pypi requests 2.32.3 pypi_0 pypi rfc3339-validator 0.1.4 pypi_0 pypi rfc3986-validator 0.1.1 pypi_0 pypi rpds-py 0.19.0 pypi_0 pypi scikit-learn 1.5.1 pypi_0 pypi scipy 1.14.0 pypi_0 pypi send2trash 1.8.3 pypi_0 pypi setuptools 69.5.1 py312h06a4308_0
six 1.16.0 pypi_0 pypi sniffio 1.3.1 pypi_0 pypi soupsieve 2.5 pypi_0 pypi spikeinterface 0.101.0rc0 pypi_0 pypi sqlite 3.45.3 h5eee18b_0
stack-data 0.6.3 pypi_0 pypi terminado 0.18.1 pypi_0 pypi threadpoolctl 3.5.0 pypi_0 pypi tinycss2 1.3.0 pypi_0 pypi tk 8.6.14 h39e8969_0
tornado 6.4.1 pypi_0 pypi tqdm 4.66.4 pypi_0 pypi traitlets 5.14.3 pypi_0 pypi types-python-dateutil 2.9.0.20240316 pypi_0 pypi tzdata 2024a h04d1e81_0
uri-template 1.3.0 pypi_0 pypi urllib3 2.2.2 pypi_0 pypi wcwidth 0.2.13 pypi_0 pypi webcolors 24.6.0 pypi_0 pypi webencodings 0.5.1 pypi_0 pypi websocket-client 1.8.0 pypi_0 pypi wheel 0.43.0 py312h06a4308_0
widgetsnbextension 4.0.11 pypi_0 pypi xz 5.4.6 h5eee18b_1
zarr 2.17.2 pypi_0 pypi zlib 1.2.13 h5eee18b_1

ianthomas23 commented 1 month ago

It looks like there is something fundamentally wrong with your environment as conda list gives different version of e.g. Matplotlib than pip list. I think you should delete this environment and start again.