Bokeh does not render any more in Jupyter lab

I am going back to a project which I use bokeh to show plots in jupyter lab. This worked when I last was working on the project, and now it does not work any more.

This is the code which does NOT render in a jupyter lab notebook:

import bokeh
print("bokeh", bokeh.__version__)
import bokeh.io
import bokeh.plotting
import numpy as np
import notebook, IPython, jupyter, jupyter_bokeh
print("notebook", notebook.__version__, "IPython", IPython.__version__, "jupyter_bokeh", jupyter_bokeh.__version__)
bokeh.io.output_notebook()

x=np.arange(100)
y1=np.random.randn(100)
y2=np.random.randn(100)
source = bokeh.models.ColumnDataSource(data=dict(x=x,y1=y1,y2=y2))
xdr = bokeh.models.Range1d(start=0, end=99)
p1 = bokeh.plotting.figure(height=100, width=600,tools="xpan,box_zoom,wheel_zoom,xbox_select,reset,undo", toolbar_location="above",x_axis_location="above", x_range=xdr)
p1.line('x', "y1", source=source)
p2 = bokeh.plotting.figure(height=100, width=600,tools="", toolbar_location=None,x_axis_location="below", x_range=xdr)
p2.line('x', "y2", source=source)
fig=bokeh.layouts.gridplot([p1,p2], ncols=1)
bokeh.plotting.show(fig)

The output is:

bokeh 3.7.3
notebook 7.4.2 IPython 9.2.0 jupyter_bokeh 4.0.5

BokehJS 3.1.1 successfully loaded.

The following is shown on the Forefox JS console:

Starting WebSocket: ws://localhost:8888/api/kernels/aa4fb177-26f0-46b8-8cc7-710a3424ea63 default.js:69:20
Keeping old LSP connection as the new kernel uses the same language notebooklspadapter.js:160:24
Bokeh: BokehJS not loaded, scheduling load and callback at 
Date Fri Jun 06 2025 16:15:33 GMT+0200 (Central European Summer Time)
jlab_core.2668b0565326e70d2bbc.js:227:13
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: all BokehJS libraries/stylesheets loaded jlab_core.2668b0565326e70d2bbc.js:233:17
Bokeh: BokehJS plotting callback run at 
Date Fri Jun 06 2025 16:15:33 GMT+0200 (Central European Summer Time)
jlab_core.2668b0565326e70d2bbc.js:308:15
[bokeh] setting log level to: 'info' bokeh-3.1.1.min.js:183:1311
Bokeh: all callbacks have finished jlab_core.2668b0565326e70d2bbc.js:211:13
[bokeh] JS/Python version mismatch bokeh-3.1.1.min.js:165:5733
[bokeh] Library versions: JS (3.1.1) / Python (3.7.3) bokeh-3.1.1.min.js:165:5777
Uncaught Error: could not resolve type 'BoxInteractionHandles', which could be due to a widget or a custom model not being registered before first usage
    y bokeh-3.1.1.min.js:211
    error bokeh-3.1.1.min.js:211
    _resolve_type bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_array bokeh-3.1.1.min.js:211
    f bokeh-3.1.1.min.js:178
    _decode_plain_array bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_array bokeh-3.1.1.min.js:211
    f bokeh-3.1.1.min.js:178
    _decode_plain_array bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_array bokeh-3.1.1.min.js:211
    f bokeh-3.1.1.min.js:178
    _decode_plain_array bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    s bokeh-3.1.1.min.js:211
    decode bokeh-3.1.1.min.js:211
    from_json bokeh-3.1.1.min.js:165
    embed_items_notebook bokeh-3.1.1.min.js:231
    embed_document debug-bokeh2.ipynb line 1 > injectedScript:5
    <anonymous> debug-bokeh2.ipynb line 1 > injectedScript:8
    <anonymous> debug-bokeh2.ipynb line 1 > injectedScript:24
    renderModel 824.85f07f87f0792b25f70b.js:1
    createRenderedMimetype widget.js:629
    createOutputItem widget.js:609
    _insertOutput widget.js:569
    onModelChanged widget.js:305
    m index.es6.js:555
    l index.es6.js:513
    emit index.es6.js:112
    _onListChanged model.js:277
    m index.es6.js:555
    l index.es6.js:513
    emit index.es6.js:112
    push observablelist.js:139
    _add model.js:226
    add model.js:146
    _onIOPub widget.js:98
    _handleIOPub future.js:236
    handleMsg future.js:205
    _handleMessage default.js:1376
    _msgChain default.js:179
    promise callback*45089/C/this._onWSMessage default.js:176
    _createSocket default.js:135
    setTimeout handler*_reconnect default.js:1457
    reconnect default.js:668
    restart default.js:638
    restartKernel sessioncontext.js:359
    restart sessioncontext.js:900
    execute index.js:1736
    execute index.es6.js:366
    g toolbar.js:1059
    s toolbar.js:682
    React 11
bokeh-3.1.1.min.js:211:113

This is really frustrating because I had exactly the same problem of the plot not rendering suddenly just a while age, see: Bokeh 3.1.1 does not render any more in jupyter notebook
How can I stop bokeh from randomly not working when Python or some other lib has to get upgraded before bitrotting commences?

OK I did upgrade python as well to 3.11.13 (from 3.7) but did not restard the jupyter command, after doing this it did work.
So upgrading both bokeh and python was the solution in this case

Well, this is immediately the issue:

bokeh 3.7.3
BokehJS 3.1.1 successfully loaded.

The version of BokehJS should always match the Python Bokeh package version. In particular, BoxInteractionHandles does not exist yet in version 3.1.1, hence the error you see. I have no idea what happened to you local system or setup that could cause this, though (I haven’t seen it occur before). Jupyter notebooks are a mess of state though, so clearing output cells and any caches is always a good thing to try.

1 Like