Cannot import 'TabPanel' from 'bokeh.models'

Hello! New user here trying to (eventually) build an output html file with tabs coming from a pandas dataframe.

My first problem is that I can’t seem to import TabPanel from bokeh.models. Other imports from .models work just fine, I’ve restarted Anaconda and I’m using Python 3.8.8 and a fresh install of bokeh.

My code so far:

import pandas as pd
from bokeh.plotting import figure, output_file, save, show
from bokeh.models import HoverTool
from bokeh.models import ColumnDataSource
from bokeh.models import TabPanel, Tabs

p1 = figure(width=300, height=300)
p1.circle([1,2,3,4,5], [6,7,2,4,5], size=20, color=‘navy’, alpha=0.5)
tab1 = TabPanel(child=p1, title=‘Circle’)

p2 = figure(width=300, height=300)
p2.line([1,2,3,4,5], [6,7,2,4,5], line_width=3, color=‘navy’, alpha=0.5)
tab2 = TabPanel(child=p2, title=‘Line’)

show(Tabs(tabs=[tab1,tab2]))

And the error message:

ImportError: cannot import name ‘TabPanel’ from ‘bokeh.models’ (C:\Users\MYNAME\Anaconda3\lib\site-packages\bokeh\models_init_.py)

I’m hopeful that it’s just something silly/easy to fix, or that I’m just doing something wrong.

Thanks for the help!

You must be running Bokeh 2.x? You can either:

  • update to Bokeh 3.0 or newer (recommended)
  • change your code to use the old 2.x API (Panel rather than TabPanel)

Thanks Bryan.

Using Panel was the easy fix I was looking for.

Now my problem is that I’ll need to update my Anaconda, and my boss has been working through IT permissions to get his updated for a month so far.

I’m not sure if it matters for your situation, but FYI you can update packages in Anaconda environments, without updating “Anaconda itself”, e.g. something like

conda create -n bk310 python=3.11 bokeh=3.1

will create a new bk310 environment that you can activate that has Bokeh 3.1 in it. I am aware of organizations that “bless” a particular version of the Anaconda installer but still let their users use conda to create whatever personal environments with whatever packages and versions that they need, from that installer. (But policies can certainly differ on whether this is acceptable or not, definitely check up front)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.