【问题标题】:How can I use Bokeh in an Azure ML notebook如何在 Azure ML 笔记本中使用散景
【发布时间】:2016-08-28 10:39:24
【问题描述】:

我可以使用 Anaconda 在我的 PC 上的 Jupyter notebook (Python 3.5) 中运行以下代码,并且运行良好。但是当我在 Azure ML 笔记本中运行相同的代码时,我得到了情节,但也得到了下面描述的错误消息。有谁知道如何在 Azure ML 笔记本中使用 Bokeh?有没有办法导入看似缺失的模块'ipykernel'

from bokeh.plotting import figure, show, output_notebook
from bokeh.sampledata.iris import flowers

colormap = {'setosa': 'red', 'versicolor': 'green', 'virginica': 'blue'}
colors = [colormap[x] for x in flowers['species']]

p = figure(title = "Iris Morphology")
p.xaxis.axis_label = 'Petal Length'
p.yaxis.axis_label = 'Petal Width'

p.circle(flowers["petal_length"], flowers["petal_width"],
     color=colors, fill_alpha=0.2, size=10)

output_notebook()
show(p)

产生情节,但也会出现以下错误

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-17-c50d1a94007e> in <module>()
 13 
 14 output_notebook()
---> 15 show(p)

/home/nbuser/env3/lib/python3.4/site-packages/bokeh/io.py in show(obj,        browser, new)
    299 
    300     '''
--> 301     return _show_with_state(obj, _state, browser, new)
    302 
    303 def _show_with_state(obj, state, browser, new):

/home/nbuser/env3/lib/python3.4/site-packages/bokeh/io.py in     _show_with_state(obj, state, browser, new)
    307 
    308     if state.notebook:
--> 309         comms_handle = _show_notebook_with_state(obj, state)
    310 
    311     elif state.server_enabled:

/home/nbuser/env3/lib/python3.4/site-packages/bokeh/io.py in     _show_notebook_with_state(obj, state)
    329         comms_target = make_id()
    330         publish_display_data({'text/html': notebook_div(obj,   comms_target)})
--> 331         handle = _CommsHandle(get_comms(comms_target), state.document,     state.document.to_json())
    332         state.last_comms_handle = handle
    333         return handle

/home/nbuser/env3/lib/python3.4/site-packages/bokeh/util/notebook.py in   get_comms(target_name)
    109 
    110     '''
--> 111     from ipykernel.comm import Comm 
    112     return Comm(target_name=target_name, data={})
    113 

ImportError: No module named 'ipykernel'

In [16]:

【问题讨论】:

    标签: python azure jupyter-notebook bokeh azure-machine-learning-studio


    【解决方案1】:

    我认为有两种选择。在笔记本中,我认为您可以使用 conda 在您的 AzureML 环境中安装新软件包,方法是执行以下单元:

    !conda install ipykernel --yes
    

    注意开头的!。在 Jupyter 笔记本中,这意味着将命令作为 shell 命令执行。

    另外,在本周晚些时候即将发布的0.12.2(今天的日期:2016-08-28) 使用 ipykernel 导入的“笔记本通讯”功能将不再是一直“打开”,只有在明确要求时才会使用。这也应该可以解决这个问题。

    【讨论】:

    • 谢谢,我不知道 !conda 命令。它现在似乎正在工作(即使没有 !conda install )所以我猜安装了 0.12.2 版本(今天是 2016-08-31)。然而,在显示图表后,整个笔记本现在变得没有响应,甚至内核重新启动都不会让它恢复活力......
    • 0.12.2 尚未发布,我会说除非您自己明确这样做,否则您是否安装了“开发人员预览版”是值得怀疑的。作为参考,可以通过检查bokeh.__version__来检查已安装的版本。同样要完全清楚,conda 是一个 shell 命令行工具,! 是一种特殊的 Jupyter notebook 方式,用于从 notebook 中执行 shell 命令。
    【解决方案2】:

    @MortenBunesGustavsen,据我所知,Azure ML notebook 有两个不同版本的 python,包括env3 主机上的python3.4anaconda3_410 主机上的python3.5。您可以直接访问 url http://notebooks.azure.com 以在 python3.5 环境中使用 Bokeh 而不会出现任何错误 ipykernel,而不是从 Azure ML studio 访问 jupyter(没有 ipykernel 的 python3.4)。

    请先通过以下代码查看运行时版本。

    In [1]: import sys
    In [2]: sys.version
    Out[2]: '3.5.1 |Anaconda custom (64-bit)| (default, Jun 15 2016, 15:32:45) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]'
    

    希望对你有帮助。

    【讨论】:

    • 成功了,谢谢!您知道如何/是否可以在此环境中将数据集从我的 Azure ML 帐户导入 Jupyter 笔记本吗?
    • 刚刚发现我可以像在其他 Jupyter 环境中一样导入数据...通过 azureml.Workspace 命令。
    猜你喜欢
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    相关资源
    最近更新 更多