I'm looking for a way to turn OFF autosave in iPython notebook. I've seen references via Google/Stack Overflow searches on how to turn ON autosave but I want the opposite (to turn OFF autosave). It would be preferential if this was something that could be set permanently rather than at the top of each notebook.
6 回答
一旦您在浏览器中使用 IPython Notebook,这将禁用自动保存:%autosave 0
.
更新:JupyterLab 现在有一个 UI 功能:https ://github.com/jupyterlab/jupyterlab/pull/3734
如果将此添加到您的custom.js
中,它将禁用所有笔记本的自动保存:
$([IPython.events]).on("notebook_loaded.Notebook", function () {
IPython.notebook.set_autosave_interval(0);
});
custom.js
位于$(ipython locate profile)/static/custom/custom.js
。您可以使用相同的方法来增加或减少自动保存间隔。该值以毫秒为单位,因此间隔 30000 表示每 30 秒自动保存一次。
MinRK 的原始解决方案已经过时,部分原因是 IPython/Jupyter 不断变化。除了这里的间接参考之外,我找不到合适的文档,但根据这个论坛帖子,现在的解决方案似乎是编辑或创建文件~/.jupyter/custom/custom.js
,并添加以下行:
Jupyter.notebook.set_autosave_interval(0); // disable autosave
这对我有用。您可以通过在启动时查找 Jupyter 笔记本右上角的简短“禁用自动保存”框来确认它是否有效。论坛帖子中的完整解决方案对我不起作用,可能是因为它不再完全有效,并且 custom.js 文件中的错误似乎无声地发生。
Windows 上 Jupyter Notebook 5.5.0 的分步解决方案(可能也适用于其他环境/版本)
找到 Jupyter 配置文件夹:
from jupyter_core.paths import jupyter_config_dir jupyter_dir = jupyter_config_dir() # C:\users\<user_name>\.jupyter on my machine
创建子文件夹
custom
,并custom.js
在其中创建文件:i.e. 'C:\users\<user_name>\.jupyter\custom\custom.js'
将以下行放入 custom.js 中:
IPython.notebook.set_autosave_interval(0);
保存文件并重新启动 Jupyter Notebook 服务器(主应用程序)。
打开笔记本时,您应该会在菜单栏的右侧短暂地看到“禁用自动保存”:
编辑jupyter notebook --version
:笔记本加载的自动保存间隔在最新版本的 Jupyter Notebook ( at 6.0.1
)中似乎不再起作用。所以我回到custom.js
解决方案:
mkdir -p ~/.jupyter/custom
echo "Jupyter.notebook.set_autosave_interval(0);" >> ~/.jupyter/custom/custom.js
正如上面Thomas Maloney所指出的,JupyterLab 现在有一个命令(在设置菜单中取消选中自动保存文档)。
在 Jupyter Notebook 中,我认为autosavetime
扩展比custom.js
文件更容易使用。该autosavetime
扩展是Jupyter 笔记本扩展的一部分,可以安装
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install
jupyter nbextension enable autosavetime/main
安装后,重新启动jupyter notebook
并转到编辑菜单中的nbextensions_config 。选择扩展名,然后关闭自动保存,如下所示:autosavetime
- 选中复选框设置笔记本加载时的自动保存间隔。如果为 false,则默认值不变。,
- 在笔记本负载上设置的自动保存间隔(以分钟为单位)输入 0 。
要测试修改:打开或创建 Python 笔记本并在新单元格中执行,
%%javascript
element.text(Jupyter.notebook.autosave_interval);
如果结果为 0,则您已成功关闭自动保存。恭喜!
从 Jupyter 4.4(2019)开始,一个可行的解决方案是将其添加到您的 custom.js 文件中:
require(['base/js/namespace', 'base/js/events'], function (Jupyter, events) {
Jupyter.notebook.set_autosave_interval(0);
console.log("Auto-save has been disabled.");
});
如果没有该require
块,javascript 将在Jupyter
对象可用之前执行,从而导致错误。
为了清楚起见,custom.js 应该位于 ~/.jupyter/custom/custom.js -custom
如果该目录不存在,则必须创建该目录。