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,使配置生效。
相关推荐
江沉晚呤时7 小时前
在 C# 中调用 Python 脚本:实现跨语言功能集成
python·microsoft·c#·.net·.netcore·.net core
电脑能手8 小时前
如何远程访问在WSL运行的Jupyter Notebook
ide·python·jupyter
Edward-tan8 小时前
CCPD 车牌数据集提取标注,并转为标准 YOLO 格式
python
老胖闲聊8 小时前
Python I/O 库【输入输出】全面详解
开发语言·python
倔强青铜三9 小时前
苦练Python第18天:Python异常处理锦囊
人工智能·python·面试
倔强青铜三9 小时前
苦练Python第17天:你必须掌握的Python内置函数
人工智能·python·面试
迷路爸爸1809 小时前
让 VSCode 调试器像 PyCharm 一样显示 Tensor Shape、变量形状、变量长度、维度信息
ide·vscode·python·pycharm·debug·调试
咸鱼鲸10 小时前
【PyTorch】PyTorch中的数据预处理操作
人工智能·pytorch·python
Dxy123931021610 小时前
Python ExcelWriter详解:从基础到高级的完整指南
开发语言·python
金玉满堂@bj10 小时前
Conda 安装包的用途
python