修改前端 JavaScript
1、在 Jupyter 配置目录下创建一个自定义的 custom.js
文件:
mkdir -p ~/.jupyter/custom
touch ~/.jupyter/custom/custom.js
2、在 custom.js
文件中添加以下 JavaScript 代码来覆盖感叹号命令的行为:
require(['base/js/namespace'], function(Jupyter) {
var old_execute = Jupyter.notebook.kernel.execute;
Jupyter.notebook.kernel.execute = function(code, callbacks, options) {
if (code.trim().startsWith('!')) {
console.warn('Usage of "!" for system commands is disabled.');
return;
}
old_execute.call(this, code, callbacks, options);
};
});
3、修改 Jupyter Notebook 配置文件 ~/.jupyter/nbconfig/notebook.json,包含对 custom.js的引用:
{ "load_extensions": { "custom/custom.js": true } } 4、重启 Jupyter Notebook,使配置生效。