【问题标题】:Can't inline Bokeh in IPython无法在 IPython 中内联散景
【发布时间】:2015-03-04 12:27:19
【问题描述】:

我安装了最新的 Bokeh 和 IPython,并尝试运行以下命令: (所有这些导入都在后面的代码中相关)

import pandas as pd
import datetime
import matplotlib.pyplot as plt
import itertools as itt
import bokeh.plotting as bk
bk.output_notebook()

xs = [0,1,2,3,4,5]
ys = [x**2 for x in xs]

p.line(xs, ys, line_width=2)
p.circle(xs,ys)
bk.show(p)

运行这两个单元后,我得到:

Javascript 错误添加输出! ReferenceError:散景未定义 有关详细信息,请参阅您的浏览器 Javascript 控制台。

所以,我运行控制台并看到了这个:

ReferenceError: Bokeh is not defined Stack trace: @http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302 line 4 > eval:1:1 .globalEval@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:4231 .domManip@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:5:21389 .append@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:5:18980 OutputArea.prototype._safe_append@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:414:13 OutputArea.prototype.append_display_data@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:534:13 OutputArea.prototype.append_output@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:320:13 OutputArea.prototype.handle_output@http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:234:9 CodeCell.prototype.get_callbacks/<.iopub.output@http://localhost:8888/static/notebook/js/codecell.js?v=20150304125302:456:21 Kernel.prototype._handle_output_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:997:13 .proxy/i@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 Kernel.prototype._handle_iopub_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:1024:13 Kernel.prototype._finish_ws_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:866:17 .proxy/i@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 deserialize@http://localhost:8888/static/services/kernels/serialize.js?v=20150304125302:60:13 Kernel.prototype._handle_ws_message@http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:857:9 .proxy/i@http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 outputarea.js:416

在看到这个之前,bk.show(p) 显示了一个扭曲的情节,说“Hello Word”,但是所有的按钮都变形了。 matplotlib 工作正常。

【问题讨论】:

    标签: python-2.7 ipython bokeh


    【解决方案1】:

    此问题已在 https://github.com/bokeh/bokeh/issues/2024 中得到解决,它将加载 BokehJS 的代码移动到 output_notebook 中,而不是在导入 bokeh 时尝试这样做。但是,我仍然建议将bk.output_notebook 放在它自己的 ipython 单元中我将尽快更新文档以反映此建议。问题是 Bokeh 使用 IPython 的“发布”机制来加载自身,如果你把其他东西放在一个也有输出的单元格中,它可能会干扰它。这就是 IPython notebook 的工作方式,除了建议将output_notebook 放在它自己的位置之外,实际上没有什么可做的,所以它的输出保证是正确的。

    【讨论】:

    【解决方案2】:

    所以,我重新启动了几次系统,并启动了一个新笔记本,突然一切正常。我猜问题出在其中一个进口产品上,但我不是 100% 确定。现在一切正常。

    【讨论】:

      【解决方案3】:

      这里的问题是Javascript函数加载在IPython.core.display中,忽略它并重新运行你的代码。

      【讨论】:

        猜你喜欢
        • 2016-05-11
        • 2015-04-23
        • 2016-04-28
        • 2015-03-01
        • 1970-01-01
        • 2015-06-16
        • 2018-07-09
        • 2017-01-03
        • 1970-01-01
        相关资源
        最近更新 更多