jupyter-widgets-contrib / ipycanvas

Interactive Canvas in Jupyter
https://ipycanvas.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
685 stars 62 forks source link

Canvas creation fails with old traitlets #295

Open tongda opened 1 year ago

tongda commented 1 year ago

run code in jupyter lab:

from ipycanvas import Canvas
Canvas(width=400, height=300)

got exception:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/traitlets/traitlets.py in get(self, obj, cls)
    527         try:
--> 528             value = obj._trait_values[self.name]
    529         except KeyError:

KeyError: '_canvas_manager'

During handling of the above exception, another exception occurred:

TraitError                                Traceback (most recent call last)
<ipython-input-2-190e315b22cc> in <module>
      1 from ipycanvas import Canvas
----> 2 Canvas(width=400, height=300)

~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/ipycanvas/canvas.py in __init__(self, *args, **kwargs)
    618     def __init__(self, *args, **kwargs):
    619         """Create a Canvas widget."""
--> 620         super(Canvas, self).__init__(*args, **kwargs)
    621 
    622         if "caching" in kwargs:

~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/ipywidgets/widgets/widget.py in __init__(self, **kwargs)
    478 
    479         Widget._call_widget_constructed(self)
--> 480         self.open()
    481 
    482     def __del__(self):

~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/ipywidgets/widgets/widget.py in open(self)
    491         """Open a comm to the frontend if one isn't already open."""
    492         if self.comm is None:
--> 493             state, buffer_paths, buffers = _remove_buffers(self.get_state())
    494 
    495             args = dict(target_name='jupyter.widget',

~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/ipywidgets/widgets/widget.py in get_state(self, key, drop_defaults)
    581         for k in keys:
    582             to_json = self.trait_metadata(k, 'to_json', self._trait_to_json)
--> 583             value = to_json(getattr(self, k), self)
    584             if not PY3 and isinstance(traits[k], Bytes) and isinstance(value, bytes):
    585                 value = memoryview(value)

~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/traitlets/traitlets.py in __get__(self, obj, cls)
    554             return self
    555         else:
--> 556             return self.get(obj, cls)
    557 
    558     def set(self, obj, value):

~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/traitlets/traitlets.py in get(self, obj, cls)
    533                 raise TraitError("No default value found for %s trait of %r"
    534                                  % (self.name, obj))
--> 535             value = self._validate(obj, dynamic_default())
    536             obj._trait_values[self.name] = value
    537             return value

~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/traitlets/traitlets.py in _validate(self, obj, value)
    589             return value
    590         if hasattr(self, 'validate'):
--> 591             value = self.validate(obj, value)
    592         if obj._cross_validation_lock is False:
    593             value = self._cross_validate(obj, value)

~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/traitlets/traitlets.py in validate(self, obj, value)
   1675             return value
   1676         else:
-> 1677             self.error(obj, value)
   1678 
   1679     def info(self):

~/archiconda3/envs/mmdeploy/lib/python3.6/site-packages/traitlets/traitlets.py in error(self, obj, value)
   1522                 % (self.name, self.info(), msg)
   1523 
-> 1524         raise TraitError(e)
   1525 
   1526 

TraitError: The '_canvas_manager' trait of a Canvas instance must be a _CanvasManager, but a value of class 'NoneType' (i.e. None) was specified.

jupyter --version:

Selected Jupyter core packages...
IPython          : 7.16.3
ipykernel        : 5.5.6
ipywidgets       : 7.7.2
jupyter_client   : 7.1.2
jupyter_core     : 4.9.2
jupyter_server   : 1.13.1
jupyterlab       : 3.2.9
nbclient         : 0.5.9
nbconvert        : 6.0.7
nbformat         : 5.1.3
notebook         : 6.4.10
qtconsole        : not installed
traitlets        : 4.3.3

jupyter labextension list:

JupyterLab v3.2.9
/home/nvidia/archiconda3/envs/mmdeploy/share/jupyter/labextensions
        ipycanvas v0.13.1 enabled OK
        @jupyter-widgets/jupyterlab-manager v3.1.1 enabled OK (python, jupyterlab_widgets)

I did a little dig into the code, it seems that the older version of traitlets (v4.3.3) has different behavior with default initialization. Since my python version is fixed to 3.6.x, I cannot install the latest jupyter and ipywidgets. Any workaround this error?

martinRenou commented 1 year ago

Thanks for opening an issue!

mattkjames7 commented 1 year ago

I had the same issue as this. My temporary work around was to downgrade to ipycanvas==12.1

athewsey commented 1 year ago

I'm also seeing this issue & downgrading to 0.12.1 seemed to un-break things.

Running on Amazon SageMaker Studio, which is showing:

IPython          : 8.1.1
ipykernel        : 6.9.2
ipywidgets       : 7.7.0
jupyter_client   : 7.1.2
jupyter_core     : 4.9.2
jupyter_server   : 1.23.2
jupyterlab       : 3.6.1
nbclient         : 0.5.13
nbconvert        : 6.5.3
nbformat         : 5.3.0
notebook         : 6.4.10
qtconsole        : not installed
traitlets        : 5.2.2

Suprising that traitlets v5 also seemed to be affected... Maybe there's something else at play? 🫤