ImportError: cannot import name 'warn' from 'bokeh.util.warnings'

492 views Asked by At

I'm trying to use panel with jupyter in VS Code but I get this error.

Here is everything that I imported to my code:

  • pandas
  • warnings
  • numpy
  • panel
  • panel.extension('tabulator')
  • hvplot.pandas

Current bokeh version is 3.1.1. I've tried with bokeh 2.4.0 and 2.4.3 but it just got worse.

Code in Jupyter:

data_slider = pn.widgets.DateRangeSlider(
    name='Periodo',
    start=df_base['DATA'].min(),
    end=df_base['DATA'].max(),
    value=(df_base['DATA'].min(), df_base['DATA'].max()),
    step=2
)
data_slider

Error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\IPython\core\formatters.py:974, in MimeBundleFormatter.__call__(self, obj, include, exclude)
    971     method = get_real_method(obj, self.print_method)
    973     if method is not None:
--> 974         return method(include=include, exclude=exclude)
    975     return None
    976 else:

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\panel\viewable.py:623, in Viewable._repr_mimebundle_(self, include, exclude)
    620     loaded = hv.extension._loaded
    622 if config.comms in ('vscode', 'ipywidgets'):
--> 623     widget = ipywidget(self)
    624     if hasattr(widget, '_repr_mimebundle_'):
    625         return widget._repr_mimebundle_(include=include, exclude=exclude), {}

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\panel\io\notebook.py:384, in ipywidget(obj, **kwargs)
    367 def ipywidget(obj: Any, **kwargs: Any):
    368     """
    369     Returns an ipywidget model which renders the Panel object.
    370 
   (...)
    382     Returns an ipywidget model which renders the Panel object.
    383     """
--> 384     from jupyter_bokeh.widgets import BokehModel
    386     from ..pane import panel
    387     model = panel(obj, **kwargs).get_root()

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\jupyter_bokeh\__init__.py:9
      5 from ._version import __version__
      7 HERE = Path(__file__).parent.resolve()
----> 9 from .widgets import BokehModel
     10 with (HERE / "labextension" / "package.json").open() as fid:
     11     data = json.load(fid)

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\jupyter_bokeh\widgets.py:33
     31 from bokeh.models import ColumnDataSource, LayoutDOM
     32 from bokeh.protocol import Protocol
---> 33 from bokeh.core.serialization import Deserializer, Serialized
     34 from bokeh.model import Model
     36 from ._version import __version__

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\bokeh\core\serialization.py:63
     47 from ..util.dataclasses import (
     48     Unspecified,
     49     dataclass,
     50     entries,
     51     is_dataclass,
     52 )
     53 from ..util.serialization import (
     54     array_encoding_disabled,
     55     convert_datetime_type,
   (...)
     61     transform_series,
     62 )
---> 63 from ..util.warnings import BokehUserWarning, warn
     64 from .types import ID
     66 if TYPE_CHECKING:

ImportError: cannot import name 'warn' from 'bokeh.util.warnings' (c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\bokeh\util\warnings.py)

EDIT: New error without changing anything.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 4
      2 import warnings
      3 import numpy as np
----> 4 import panel as pn
      5 pn.extension('tabulator')
      6 import hvplot.pandas

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\panel\__init__.py:48
      1 """
      2 Panel is a high level app and dashboarding framework
      3 ====================================================
   (...)
     46 https://panel.holoviz.org/getting_started/index.html
     47 """
---> 48 from . import layout  # noqa
     49 from . import links  # noqa
     50 from . import pane  # noqa

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\panel\layout\__init__.py:31
      1 """
      2 Layout
      3 ======
   (...)
     29 https://panel.holoviz.org/getting_started/index.html
     30 """
---> 31 from .accordion import Accordion  # noqa
     32 from .base import (  # noqa
     33     Column, ListLike, ListPanel, Panel, Row, WidgetBox,
     34 )
     35 from .card import Card  # noqa

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\panel\layout\accordion.py:9
      5 import param
      7 from bokeh.models import Column as BkColumn, CustomJS
----> 9 from .base import NamedListPanel
     10 from .card import Card
     12 if TYPE_CHECKING:

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\panel\layout\base.py:17
     13 import param
     15 from bokeh.models import Column as BkColumn, Row as BkRow
---> 17 from ..io.model import hold
     18 from ..io.state import state
     19 from ..reactive import Reactive

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\panel\io\__init__.py:9
      7 from .cache import cache  # noqa
      8 from .callbacks import PeriodicCallback  # noqa
----> 9 from .document import init_doc, unlocked, with_lock  # noqa
     10 from .embed import embed_state  # noqa
     11 from .logging import panel_logger  # noqa

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\panel\io\document.py:20
     17 from bokeh.document.document import Document
     18 from bokeh.document.events import DocumentChangedEvent, ModelChangedEvent
---> 20 from .model import monkeypatch_events
     21 from .state import curdoc_locked, state
     23 logger = logging.getLogger(__name__)

File c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\panel\io\model.py:20
     16 from bokeh.document.events import (
     17     ColumnDataChangedEvent, DocumentPatchedEvent, ModelChangedEvent,
     18 )
     19 from bokeh.model import DataModel
---> 20 from bokeh.models import Box, ColumnDataSource, Model
     21 from bokeh.protocol import Protocol
     22 from typing_extensions import Literal

ImportError: cannot import name 'Box' from 'bokeh.models' (c:\Users\acunha\AppData\Local\Programs\Python\Python311\Lib\site-packages\bokeh\models\__init__.py)
1

There are 1 answers

0
martinolmos On

I had the same issue. What worked for me was reinstalling the following packages with these specific versions:

pip install panel==0.14.4, bokeh==2.4.3, jupyter-bokeh==2.0.4

Hope this helps.