IPython/Jupyter Installing Extensions

不羁的心 提交于 2019-12-01 08:48:34

问题


I'm having troubles installing extensions in IPython. The problem is that i can't get the extensions load automatically, i have followed the instructions in the github page but it just doesn't work. According the the homepage i need to modify the custom.js file by adding some lines. I want to install the codefolding, hide_input_all and runtools extensions. This is how my custom.js file looks:

// activate extensions only after Notebook is initialized
require(["base/js/events"], function (events) {
$([IPython.events]).on("app_initialized.NotebookApp", function () {
 /* load your extension here */
 IPython.load_extensions('usability/codefolding/codefolding')
 IPython.load_extensions('usability/runtools/runtools')
 require(['/static/custom/hide_input_all.js'])
 });
});

The extensions work well if i call them manually, for example, if i type

%%javascript
IPython.load_extensions('usability/runtools/runtools/main');

the runtools appear and works perfectly, but i want the extensions to be loaded automatically and not to have to call them manually every time. Could someone tell me where is my mistake?


回答1:


There's been a little change to the syntax. Nowadays, $ might not be defined by the time your custom.js loads, so instead of something like

$([IPython.events]).on("app_initialized.NotebookApp", function () {
    IPython.load_extensions("whatever");
});

you should do something like

require(['base/js/namespace', 'base/js/events'], function(IPython, events) {
    events.on('app_initialized.NotebookApp', function(){
        IPython.load_extensions("whatever");
    })
});

with the appropriate changes to braces and parentheses. For me, the former will work more often than not, but certainly not always; it fails maybe ~1/3 of the time.

If that doesn't do it for you, open up Developer Tools (or whatever is relevant for your browser) and look at the javascript console for errors. That'll help figure out what's going wrong.



来源:https://stackoverflow.com/questions/29220909/ipython-jupyter-installing-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!