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,使配置生效。
相关推荐
Q一件事8 分钟前
结构方程相关
python·算法·机器学习
wjhx8 分钟前
vscode中加入Claude Code,对接deepseek
ide·vscode·编辑器
SunnyDays101119 分钟前
使用 Python 轻松操控 Excel 网格线:隐藏、显示与自定义颜色
开发语言·python·excel
BubbleCodes21 分钟前
使用Conda和pip创建Python环境
python·conda·pip
我不听你讲话28 分钟前
Nginx核心功能
linux·服务器·python
计算机徐师兄32 分钟前
Python基于数字水印的图像版权保护系统(附源码,文档说明)
python·数字水印·图像版权保护系统·python图像版权保护系统·python数字水印图像版权·python数字水印·数字水印图像版权保护系统
小陳参上38 分钟前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python
蜡台39 分钟前
VSCode 配置PHP开发环境
ide·vscode·php·debug·launch.json
李昊哲小课39 分钟前
Python 线性数据结构详解
开发语言·数据结构·python
新诺韦尔API41 分钟前
身份证验证接口详细开发对接指南
大数据·python·api