2017-08-04 149 views
0

我已經嘗試了一個簡單的內聯教程,並使用cookiecutter模板來製作Jupyter小部件,但不加載小部件。無法加載Jupyter筆記本中的自定義小部件

當我嘗試這個tutorial即使是hello世界小部件,我也只是打印出「Jupyter Widget」,並在控制檯中獲得「404 GET /nbextensions/widgets/notebook/js/extension.js」。

當我嘗試內嵌例子,我在控制檯中「404 GET /static/@jupyter-widgets/base.js」爲直列例子的代碼此錯誤只是

import ipywidgets as widgets 
from traitlets import Unicode, validate 


class HelloWidget(widgets.DOMWidget): 
    _view_name = Unicode('HelloView').tag(sync=True) 
    _view_module = Unicode('hello').tag(sync=True) 
    _view_module_version = Unicode('0.1.0').tag(sync=True) 

%%javascript 
require.undef('hello'); 

define('hello', ["@jupyter-widgets/base"], function(widgets) { 

    var HelloView = widgets.DOMWidgetView.extend({ 

    // Render the view. 
    render: function() { 
     this.el.textContent = 'Hello World!'; 
    }, 
    }); 

    return { 
     HelloView: HelloView 
    }; 
}); 

這是在conda虛擬環境中,Jupyter 4.2.1和筆記本4.3.1

在此先感謝您的幫助。

回答

0

我在使用pip安裝後忘記運行jupyter nbextension enable --py widgetsnbextension時遇到了同樣的問題;詳情請看這裏http://ipywidgets.readthedocs.io/en/latest/user_install.html。好像conda應該爲你啓用了擴展。我沒有任何與conda的經驗,但似乎你可以通過conda install -c anaconda ipywidgetsconda install -c conda-forge ipywidgets安裝ipywidgets,想想也許conda-forge安裝可能會更新?

0

重新安裝所有jupyter和ipython相關的pip軟件包爲我解決了這個問題。