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,使配置生效。
相关推荐
仙俊红4 分钟前
Java JUC:CompletableFuture 详解,多个任务并行执行并等待全部完成
java·python·spring
学习3人组6 分钟前
Python 评论朴素贝叶斯文本情感分析示例
人工智能·python·机器学习
2401_8856651911 分钟前
从零搭建卷积神经网络:基于PyTorch实现MNIST手写数字分类
pytorch·python·神经网络·算法·机器学习·分类·cnn
SilentSamsara15 分钟前
MLflow 实验追踪与模型注册:从实验到生产的可复现工作流
开发语言·人工智能·pytorch·python·青少年编程
曲幽16 分钟前
写爬虫时用了代理还被封?Python 代理的那些隐藏坑,我替你踩明白了
python·http·https·proxy·socks·requests·socks5·proxies
装不满的克莱因瓶16 分钟前
掌握多头自注意力机制(Multi-Head Self-Attention)——Transformer 强大表达能力的核心来源
人工智能·python·深度学习·数学·ai·transformer
下班走回家23 分钟前
RAG 技术的进化:从朴素检索到 Agentic RAG
开发语言·人工智能·python
用什么都重名31 分钟前
Python文本匹配利器:FlashText与RapidFuzz深度对比
python·flash text·rapidfuzz
@Ma32 分钟前
Python 实现企业微信外部群主动消息发送及成功接入后如何避坑,避免风控封号
开发语言·python·企业微信
DXM052132 分钟前
第10期| 卷积神经网络CNN通俗详解:AI遥感的底层核心
人工智能·python·神经网络·机器学习·arcgis·cnn·文心一言