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,使配置生效。
相关推荐
Sunhen_Qiletian17 分钟前
python语言应用实战--------网络爬虫篇 第二篇(selenium库)
爬虫·python·selenium
焚 城37 分钟前
Visual Studio 2026来临
ide·visual studio
鄃鳕1 小时前
装饰器【Python】
开发语言·python·数码相机
m0_528489252 小时前
Pycharm修改系统缓存路径(包含config, system, plugins, logs, remote sources等)
ide·python·pycharm·c盘
Franklin2 小时前
AI Coding 基础实践03 - Trae AI在Pycharm中的使用02 - 读取不了项目的文件问题解决
ide·python·pycharm
胖墩会武术2 小时前
【OpenCV图像处理】深度学习:cv2.dnn() —— 图像分类、人脸检测、目标检测
图像处理·pytorch·python·opencv
帮帮志2 小时前
PyCharm 开发工具 不同的模式
ide·python·pycharm
Xiaok10182 小时前
在 Jupyter Notebook 中启动 TensorBoard
人工智能·python·jupyter
趙卋傑2 小时前
接口自动化测试
python·pycharm·pytest