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

Issues handling Matplotlib backend settings #347

Closed
rhkarls opened this issue Dec 14, 2021 · 2 comments
Closed

Issues handling Matplotlib backend settings #347

rhkarls opened this issue Dec 14, 2021 · 2 comments
Milestone

Comments

@rhkarls
Copy link

rhkarls commented Dec 14, 2021

Not sure if this the correct place to report this, but I'm getting this error in the Spyder console using a custom interpreter. I do not get the error with other interpreters with the same versions of matplotlib and IPython, so not really sure why this happens.

Edit: realizing a made a typo when creating the env and pyqt was not installed causing this error - sorry about that. Leaving the issue here as perhaps this should be dealt with in a more clear way for the user, and also that choosing TkAgg or Automatic gets stuck. After properly installing pyqt choosing Automatic works, as Qt5Agg can be used.

Error, appears when starting a console:

Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:15:42) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython  -- An enhanced Interactive Python.

Output from spyder call 'show_mpl_backend_errors':

=========================================================================
NOTE: The following error appeared when setting your Matplotlib backend!!
=========================================================================

Traceback (most recent call last):
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\spyder_kernels\console\kernel.py", line 723, in _set_mpl_backend
    get_ipython().run_line_magic(magic, backend)
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\IPython\core\interactiveshell.py", line 2364, in run_line_magic
    result = fn(*args, **kwargs)
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\IPython\core\magic.py", line 187, in <lambda>
    call = lambda f, *a, **k: f(*a, **k)
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\IPython\core\magics\pylab.py", line 99, in matplotlib
    gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\IPython\core\interactiveshell.py", line 3546, in enable_matplotlib
    pt.activate_matplotlib(backend)
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\IPython\core\pylabtools.py", line 357, in activate_matplotlib
    from matplotlib import pyplot as plt
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\matplotlib\pyplot.py", line 2230, in <module>
    switch_backend(rcParams["backend"])
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\matplotlib\pyplot.py", line 267, in switch_backend
    class backend_mod(matplotlib.backend_bases._Backend):
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\matplotlib\pyplot.py", line 268, in backend_mod
    locals().update(vars(importlib.import_module(backend_name)))
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 5, in <module>
    from .backend_qtagg import (
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\matplotlib\backends\backend_qtagg.py", line 9, in <module>
    from .qt_compat import QT_API, _enum, _setDevicePixelRatio
  File "C:\Users\username\Miniconda3\envs\cf_geo\lib\site-packages\matplotlib\backends\qt_compat.py", line 128, in <module>
    raise ImportError("Failed to import any qt binding")
ImportError: Failed to import any qt binding

Happens with Spyder 5.2.0 and 5.2.1 installed with Windows installers.
Output of conda list for the particular env:

# packages in environment at C:\Users\username\Miniconda3\envs\cf_geo:
#
# Name                    Version                   Build  Channel
attrs                     21.2.0             pyhd8ed1ab_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
blosc                     1.21.0               h0e60522_0    conda-forge
boost-cpp                 1.74.0               h5b4e17d_5    conda-forge
branca                    0.4.2              pyhd8ed1ab_0    conda-forge
brotli                    1.0.9                h8ffe710_6    conda-forge
brotli-bin                1.0.9                h8ffe710_6    conda-forge
brotlipy                  0.7.0           py39hb82d6ee_1003    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2021.10.8            h5b45459_0    conda-forge
cairo                     1.16.0            h15b3021_1009    conda-forge
certifi                   2021.10.8        py39hcbf5309_1    conda-forge
cffi                      1.15.0           py39h0878f49_0    conda-forge
cfitsio                   4.0.0                hd67004f_0    conda-forge
charset-normalizer        2.0.9              pyhd8ed1ab_0    conda-forge
click                     8.0.3            py39hcbf5309_1    conda-forge
click-plugins             1.1.1                      py_0    conda-forge
cligj                     0.7.2              pyhd8ed1ab_1    conda-forge
cloudpickle               2.0.0              pyhd8ed1ab_0    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
cryptography              36.0.0           py39h7bc7c5c_0    conda-forge
curl                      7.80.0               h789b8ee_1    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
debugpy                   1.5.1            py39h415ef7b_0    conda-forge
decorator                 5.1.0              pyhd8ed1ab_0    conda-forge
entrypoints               0.3             pyhd8ed1ab_1003    conda-forge
expat                     2.4.1                h39d44d4_0    conda-forge
fiona                     1.8.20           py39hd99abff_4    conda-forge
folium                    0.12.1.post1       pyhd8ed1ab_1    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.13.1            h1989441_1005    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.28.3           py39hb82d6ee_0    conda-forge
freetype                  2.10.4               h546665d_1    conda-forge
freexl                    1.0.6                ha8e266a_0    conda-forge
gdal                      3.4.0           py39h3f5efd6_12    conda-forge
geopandas                 0.10.2             pyhd8ed1ab_1    conda-forge
geopandas-base            0.10.2             pyha770c72_1    conda-forge
geos                      3.10.1               h39d44d4_1    conda-forge
geotiff                   1.7.0                hc8731e1_5    conda-forge
gettext                   0.19.8.1          ha2e2712_1008    conda-forge
hdf4                      4.2.15               h0e5069d_3    conda-forge
hdf5                      1.12.1          nompi_h2a0e4a3_103    conda-forge
icu                       69.1                 h0e60522_0    conda-forge
idna                      3.1                pyhd3deb0d_0    conda-forge
intel-openmp              2021.4.0          h57928b3_3556    conda-forge
ipykernel                 6.6.0            py39h832f523_0    conda-forge
ipython                   7.30.1           py39hcbf5309_0    conda-forge
jbig                      2.1               h8d14728_2003    conda-forge
jedi                      0.18.1           py39hcbf5309_0    conda-forge
jinja2                    3.0.3              pyhd8ed1ab_0    conda-forge
joblib                    1.1.0              pyhd8ed1ab_0    conda-forge
jpeg                      9d                   h8ffe710_0    conda-forge
jupyter_client            7.1.0              pyhd8ed1ab_0    conda-forge
jupyter_core              4.9.1            py39hcbf5309_1    conda-forge
kealib                    1.4.14               h8995ca9_3    conda-forge
kiwisolver                1.3.2            py39h2e07f2f_1    conda-forge
krb5                      1.19.2               h20d022d_3    conda-forge
lcms2                     2.12                 h2a16943_0    conda-forge
lerc                      3.0                  h0e60522_0    conda-forge
libblas                   3.9.0              12_win64_mkl    conda-forge
libbrotlicommon           1.0.9                h8ffe710_6    conda-forge
libbrotlidec              1.0.9                h8ffe710_6    conda-forge
libbrotlienc              1.0.9                h8ffe710_6    conda-forge
libcblas                  3.9.0              12_win64_mkl    conda-forge
libcurl                   7.80.0               h789b8ee_1    conda-forge
libdeflate                1.8                  h8ffe710_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libgdal                   3.4.0               hf8fe220_12    conda-forge
libglib                   2.70.2               h3be07f2_0    conda-forge
libiconv                  1.16                 he774522_0    conda-forge
libkml                    1.3.0             h9859afa_1014    conda-forge
liblapack                 3.9.0              12_win64_mkl    conda-forge
libnetcdf                 4.8.1           nompi_h1cc8e9d_101    conda-forge
libpng                    1.6.37               h1d00b33_2    conda-forge
libpq                     14.1                 hfcc5ef8_1    conda-forge
librttopo                 1.1.0                he35e8ac_8    conda-forge
libsodium                 1.0.18               h8d14728_1    conda-forge
libspatialindex           1.9.3                h39d44d4_4    conda-forge
libspatialite             5.0.1               hf126459_12    conda-forge
libssh2                   1.10.0               h680486a_2    conda-forge
libtiff                   4.3.0                hd413186_2    conda-forge
libwebp-base              1.2.1                h8ffe710_0    conda-forge
libxml2                   2.9.12               hf5bbc77_1    conda-forge
libzip                    1.8.0                hfed4ece_1    conda-forge
libzlib                   1.2.11            h8ffe710_1013    conda-forge
lz4-c                     1.9.3                h8ffe710_1    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
mapclassify               2.4.3              pyhd8ed1ab_0    conda-forge
markupsafe                2.0.1            py39hb82d6ee_1    conda-forge
matplotlib-base           3.5.1            py39h581301d_0    conda-forge
matplotlib-inline         0.1.3              pyhd8ed1ab_0    conda-forge
mkl                       2021.4.0           h0e2418a_729    conda-forge
msys2-conda-epoch         20160418                      1    conda-forge
munch                     2.5.0                      py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
nest-asyncio              1.5.4              pyhd8ed1ab_0    conda-forge
networkx                  2.6.3              pyhd8ed1ab_1    conda-forge
numpy                     1.21.4           py39h6635163_0    conda-forge
olefile                   0.46               pyh9f0ad1d_1    conda-forge
openjpeg                  2.4.0                hb211442_1    conda-forge
openssl                   1.1.1l               h8ffe710_0    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
pandas                    1.3.5            py39h2e25243_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pcre                      8.45                 h0e60522_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    8.4.0            py39h916092e_0    conda-forge
pip                       21.3.1             pyhd8ed1ab_0    conda-forge
pixman                    0.40.0               h8ffe710_0    conda-forge
poppler                   21.11.0              h24fffdf_0    conda-forge
poppler-data              0.4.11               hd8ed1ab_0    conda-forge
postgresql                14.1                 h1c22c4f_1    conda-forge
proj                      8.2.0                h1cfcee9_0    conda-forge
prompt-toolkit            3.0.24             pyha770c72_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pygments                  2.10.0             pyhd8ed1ab_0    conda-forge
pyopenssl                 21.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.6              pyhd8ed1ab_0    conda-forge
pyproj                    3.3.0            py39h312c5a8_0    conda-forge
pysocks                   1.7.1            py39hcbf5309_4    conda-forge
python                    3.9.7           h7840368_3_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.9                      2_cp39    conda-forge
pytz                      2021.3             pyhd8ed1ab_0    conda-forge
pywin32                   302              py39hb82d6ee_2    conda-forge
pyzmq                     22.3.0           py39he46f08e_1    conda-forge
requests                  2.26.0             pyhd8ed1ab_1    conda-forge
rtree                     0.9.7            py39h09fdee3_3    conda-forge
scikit-learn              1.0.1            py39he931e04_2    conda-forge
scipy                     1.7.3            py39hc0c34ad_0    conda-forge
setuptools                59.4.0           py39hcbf5309_0    conda-forge
shapely                   1.8.0            py39h1db6edd_4    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
spyder-kernels            2.2.0            py39hcbf5309_0    conda-forge
sqlite                    3.37.0               h8ffe710_0    conda-forge
tbb                       2021.4.0             h2d74725_1    conda-forge
threadpoolctl             3.0.0              pyh8a188c0_0    conda-forge
tiledb                    2.5.2                h95dad36_0    conda-forge
tk                        8.6.11               h8ffe710_1    conda-forge
tornado                   6.1              py39hb82d6ee_2    conda-forge
traitlets                 5.1.1              pyhd8ed1ab_0    conda-forge
tzdata                    2021e                he74cb21_0    conda-forge
ucrt                      10.0.20348.0         h57928b3_0    conda-forge
urllib3                   1.26.7             pyhd8ed1ab_0    conda-forge
vc                        14.2                 hb210afc_5    conda-forge
vs2015_runtime            14.29.30037          h902a5da_5    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
wheel                     0.37.0             pyhd8ed1ab_1    conda-forge
win_inet_pton             1.1.0            py39hcbf5309_3    conda-forge
xerces-c                  3.2.3                h0e60522_4    conda-forge
xyzservices               2021.11.0          pyhd8ed1ab_1    conda-forge
xz                        5.2.5                h62dcd97_1    conda-forge
zeromq                    4.3.4                h0e60522_1    conda-forge
zlib                      1.2.11            h8ffe710_1013    conda-forge
zstd                      1.5.0                h6255e5f_0    conda-forge

Spyder dependencies:

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree                  :  None (OK)
IPython >=7.6.0               :  7.30.1 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.8.9 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.4.0 (OK)
nbconvert >=4.0               :  6.3.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
paramiko >=2.4.0              :  2.8.1 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.10.0 (OK)
pylint >=2.5.0                :  2.12.2 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.3.2;<1.4.0          :  1.3.3 (OK)
pylsp_black >=1.0.0           :  1.0.1 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.1.1 (OK)
qtconsole >=5.2.1;<5.3.0      :  5.2.2 (OK)
qtpy >=1.5.0                  :  1.11.3 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  59.6.0 (OK)
sphinx >=0.6.6                :  4.3.1 (OK)
spyder_kernels >=2.2.0;<2.3.0 :  2.2.0 (OK)
textdistance >=4.2.0          :  4.2.2 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog                      :  2.1.6 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  0.29.25 (OK)
matplotlib >=2.0.0            :  3.5.1 (OK)
numpy >=1.7                   :  1.19.3 (OK)
pandas >=1.1.1                :  1.3.5 (OK)
scipy >=0.17.0                :  1.7.3 (OK)
sympy >=0.7.3                 :  1.9 (OK)

Edit: I had backend set to Qt5 when this happens.
Other backends:
Inline: works as expected
Automatic: stuck on "connecting to kernel..."
Qt5: error as above
Qt4: KeyError (I guess Qt4 is not supported with mpl version I'm using)
Tkinter: stuck on "connecting to kernel..." (tk installed, possibly due to matplotlib error ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'qt' is currently running ?)

@rhkarls rhkarls changed the title Error setting matplotlib backend: ImportError: Failed to import any qt binding Issues handling matplotlib backend settings Dec 15, 2021
@ccordoba12
Copy link
Member

Tkinter: stuck on "connecting to kernel..."

Hey @rhkarls, thanks for reporting. Perhaps Matplotlib changed the way it sets its backend in its 3.5 version. We'll take a look at it.

@ccordoba12 ccordoba12 added this to the v2.2.1 milestone Dec 15, 2021
@ccordoba12 ccordoba12 changed the title Issues handling matplotlib backend settings Issues handling Matplotlib backend settings Dec 19, 2021
@ccordoba12
Copy link
Member

Edit: realizing a made a typo when creating the env and pyqt was not installed causing this error - sorry about that. Leaving the issue here as perhaps this should be dealt with in a more clear way for the user

Thanks @rhkarls for the pointer! I improved our error message for missing modules in PR #368.

Automatic: stuck on "connecting to kernel..."

This falls back to Tkinter if PyQt5 can't be found (see below).

Qt4: KeyError (I guess Qt4 is not supported with mpl version I'm using)

You're right. I'll remove that option in 5.3.0, to be released in a couple of months,

Tkinter: stuck on "connecting to kernel..."

This was fixed in #360.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants