ipympl icon indicating copy to clipboard operation
ipympl copied to clipboard

DeprecationWarning with traitlets when using %matplotlib widget

Open maij opened this issue 4 years ago • 1 comments

Describe the issue

It seems that the widget backend is doing something that is deprecated, and I thought I should make a note of it here. Example:

import warnings
import matplotlib.pyplot as plt

%matplotlib widget
warnings.simplefilter("always", DeprecationWarning) 
plt.subplots()

I get the following warnings

/home/maij/.local/lib/python3.6/site-packages/ipywidgets/widgets/widget.py:412: DeprecationWarning: Passing unrecoginized arguments to super(Canvas).__init__().
__init__() missing 1 required positional argument: 'figure'
This is deprecated in traitlets 4.2.This error will be raised in a future release of traitlets.
  super(Widget, self).__init__(**kwargs)
/home/maij/.local/lib/python3.6/site-packages/ipywidgets/widgets/widget.py:412: DeprecationWarning: Passing unrecoginized arguments to super(Toolbar).__init__().
__init__() missing 1 required positional argument: 'canvas'
This is deprecated in traitlets 4.2.This error will be raised in a future release of traitlets.
  super(Widget, self).__init__(**kwargs)

Versions

 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0]
ipympl version: 0.5.6
jupyter core     : 4.6.3
jupyter-notebook : 6.0.3
qtconsole        : 4.7.4
ipython          : 7.13.0
ipykernel        : 5.2.0
jupyter client   : 6.1.3
jupyter lab      : 2.1.4
nbconvert        : 6.0.0a0
ipywidgets       : 7.5.1
nbformat         : 5.0.4
traitlets        : 4.3.3
JupyterLab v2.1.4
Known labextensions:
   app dir: /usr/local/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
        @jupyter-widgets/jupyterlab-sidecar v0.5.0  enabled  OK
        jupyter-matplotlib v0.7.2  enabled  OK
        shared_kernel v0.1.0  enabled  OK

maij avatar Jun 16 '20 09:06 maij

This happened to me today as well. I have isolated the problem to import kornia. Before I import this package, I have no warnings. When I import this package, the warnings start to appear. Probably they do something funky in their package. I have submitted an issue to kornia with link to this issue.

Quick workaround

For anybody who needs a quick solution, just suppress the warning with:

import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning) 

Steps to reproduce

virtualenv .venv
pip install jupyter-lab
pip insatll kornia
jupyter-lab

Inside your Jupyter Lab create a new Python3 notebook and there write the following code:

# cell 1
%matplotlib widget
import matplotlib.pyplot as plt
# cell 2
plt.figure()
plt.close()

No warnings, no problems.

# cell 3
import kornia
plt.figure()
plt.close()

Outputs:

/somepath/.venv/lib/python3.8/site-packages/ipywidgets/widgets/widget.py:412: DeprecationWarning: Passing unrecognized arguments to super(Toolbar).init(). init() missing 1 required positional argument: 'canvas' This is deprecated in traitlets 4.2.This error will be raised in a future release of traitlets. super(Widget, self).init(**kwargs)

Versions

3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0]
ipympl version: 0.8.1
Selected Jupyter core packages...
IPython          : 7.28.0
ipykernel        : 6.4.2
ipywidgets       : 7.6.5
jupyter_client   : 7.0.6
jupyter_core     : 4.8.1
jupyter_server   : 1.11.1
jupyterlab       : 3.2.1
nbclient         : 0.5.4
nbconvert        : 6.2.0
nbformat         : 5.1.3
notebook         : 6.4.5
qtconsole        : 5.1.1
traitlets        : 5.1.0

Known nbextensions:
  config dir: /home/<user>/.jupyter/nbconfig
    notebook section
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
  config dir: /home/<user>/<path to venv>/.venv/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
JupyterLab v3.2.1
/home/<user>/<path to venv>/.venv/share/jupyter/labextensions
        jupyter-matplotlib v0.10.1 enabled OK
        @jupyter-widgets/jupyterlab-manager v3.0.1 enabled OK (python, jupyterlab_widgets)

Other labextensions (built into JupyterLab)
   app dir: /home/<user>/<path to venv>/.venv/share/jupyter/lab

paloha avatar Oct 22 '21 20:10 paloha