【问题标题】:Python Bokeh Version 0.13.0 RangeTool import errorPython Bokeh 版本 0.13.0 RangeTool 导入错误
【发布时间】:2018-09-08 20:22:14
【问题描述】:
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'”

我该如何解决这个错误?

【问题讨论】:

    标签: python import jupyter-notebook bokeh importerror


    【解决方案1】:

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

    print(bokeh.__version__) 
    

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

    【讨论】:

    • 非常感谢!我可以通过简单的卸载和安装来解决这个问题。
    猜你喜欢
    • 2016-03-09
    • 2021-03-07
    • 2016-07-16
    • 2017-11-01
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 2013-11-06
    相关资源
    最近更新 更多