PythonBokeh Version 0.13.0 RangeTool导入错误

Python Bokeh Version 0.13.0 RangeTool import error

import numpy as np

from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, RangeTool
from bokeh.plotting import figure
from bokeh.sampledata.stocks import AAPL

dates = np.array(AAPL['date'], dtype=np.datetime64)
source = ColumnDataSource(data=dict(date=dates, close=AAPL['adj_close']))

p = figure(plot_height=300, plot_width=800, tools="", toolbar_location=None,
       x_axis_type="datetime", x_range=(dates[1500], dates[2500]))

p.line('date', 'close', source=source)
p.yaxis.axis_label = 'Price'

select = figure(plot_height=150, plot_width=800, y_range=p.y_range,
            x_axis_type="datetime", y_axis_type=None,
            tools="", toolbar_location=None)
range_rool = RangeTool(x_range=p.x_range)
range_rool.overlay.fill_color = "navy"
range_rool.overlay.fill_alpha = 0.2

select.line('date', 'close', source=source)
select.ygrid.grid_line_color = None
select.add_tools(range_rool)
select.toolbar.active_multi = range_rool

show(column(p, select))

使用 Python 3.6,Bokeh 0.13.0,Juptyer 5.5.0

尝试了 运行 这个代码,但是它给了我 "ImportError: cannot import name 'RangeTool' "

我该如何解决这个错误?

如果您无法导入 RangeTool 那么您 100% 遇到了某种安装问题。一个常见的事情是将 Bokeh 0.13.0 安装在与您当前 运行ning Python 不同的 Python 环境中(可能是无意中)。这特别是与笔记本一起使用时很常见。我见过很多人在与笔记本不同的环境中安装 Bokeh,因此当他们 运行 笔记本时,它当然会看到其他一些较旧的 Bokeh 版本。你总是可以执行

print(bokeh.__version__) 

确认您实际使用的是您认为正在使用的版本。否则,如果报告 0.13.0 那么安装就会以某种方式搞砸。清除 site-packages 中与 Bokeh 相关的所有内容并重新安装。