Jupyter如何优雅禁止termin

修改前端 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,使配置生效。
相关推荐
bst@微胖子16 分钟前
Python高级语法之selenium
开发语言·python·selenium
查理零世1 小时前
【蓝桥杯集训·每日一题2025】 AcWing 6118. 蛋糕游戏 python
python·算法·蓝桥杯
魔尔助理顾问2 小时前
一个简洁高效的Flask用户管理示例
后端·python·flask
java1234_小锋2 小时前
一周学会Flask3 Python Web开发-request请求对象与url传参
开发语言·python·flask·flask3
诚信爱国敬业友善6 小时前
常见排序方法的总结归类
开发语言·python·算法
罗政6 小时前
冒险岛079 V8 整合版源码搭建教程+IDEA启动
java·ide·intellij-idea
架构默片7 小时前
【JAVA工程师从0开始学AI】,第五步:Python类的“七十二变“——当Java的铠甲遇见Python的液态金属
java·开发语言·python
小哥山水之间8 小时前
在 Python 中操作 Excel 文件
开发语言·python·excel
艾斯比的日常8 小时前
VSCode 实用快捷键
ide·vscode·编辑器
Galaxy_12298 小时前
vscode远程报错:Remote host key has changed,...
ide·vscode·编辑器