IPython/Jupyter安装扩展 [英] IPython/Jupyter Installing Extensions

查看:101
本文介绍了IPython/Jupyter安装扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IPython中安装扩展程序遇到了麻烦.问题是我无法自动加载扩展,我已经按照github页上的说明进行操作,但它不起作用.根据主页,我需要通过添加一些行来修改custom.js文件.我想安装代码折叠,hide_input_all和runtools扩展.这是我的custom.js文件的外观:

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');

runtools出现并运行完美,但是我希望这些扩展能够自动加载,而不必每次都手动调用它们.有人可以告诉我我的错误在哪里吗?

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?

推荐答案

语法有所变化.如今,$可能尚未在custom.js加载时定义,因此它不是类似

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");
});

您应该做类似的事情

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

对括号和括号进行适当的更改.对我来说,前者会经常工作,但肯定不会总是如此.它可能会失败大约1/3的时间.

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.

如果这样做不适合您,请打开开发人员工具(或与您的浏览器相关的任何工具),然后查看javascript控制台中的错误.这将有助于找出问题所在.

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.

这篇关于IPython/Jupyter安装扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆