简体   繁体   English

在IPython Notebook中关闭自动保存

[英]Turn Off Autosave in IPython Notebook

I'm looking for a way to turn OFF autosave in iPython notebook. 我正在寻找一种在iPython笔记本中关闭自动保存的方法。 I've seen references via Google/Stack Overflow searches on how to turn ON autosave but I want the opposite (to turn OFF autosave). 我已经通过Google / Stack Overflow搜索看到了有关如何打开自动保存的参考,但是我想相反(关闭自动保存)。 It would be preferential if this was something that could be set permanently rather than at the top of each notebook. 如果可以永久设置而不是在每个笔记本的顶部进行设置,那将是比较可取的。

This will disable autosave once you're in IPython Notebook in the browser: %autosave 0 . 一旦您在浏览器中的IPython Notebook中,将禁用自动保存: %autosave 0

Update : There is now a UI feature in JupyterLab: https://github.com/jupyterlab/jupyterlab/pull/3734 更新 :JupyterLab中现在有一个UI功能: https : //github.com/jupyterlab/jupyterlab/pull/3734

If you add this to your custom.js , it will disable autosave for all notebooks: 如果将其添加到custom.js ,它将禁用所有笔记本的自动保存:

$([IPython.events]).on("notebook_loaded.Notebook", function () {
  IPython.notebook.set_autosave_interval(0);
});

custom.js is found at $(ipython locate profile)/static/custom/custom.js . custom.js在发现$(ipython locate profile)/static/custom/custom.js You can use the same thing to increase or decrease the autosave interval. 您可以使用同一件事来增加或减少自动保存间隔。 The value is in milliseconds, so an interval of 30000 means autosave every thirty seconds. 该值以毫秒为单位,因此间隔30000表示每三十秒自动保存一次。

The original solution from MinRK is outdated, partly because IPython/Jupyter keeps changing so much. MinRK最初的解决方案已经过时,部分原因是IPython / Jupyter一直在变化很大。 I can't find proper documentation for this, other than an indirect reference here , but according to this forum post , the solution now seems to be to edit or create the file ~/.jupyter/custom/custom.js , and add the line: 除了这里的间接参考,我找不到合适的文档,但是根据此论坛帖子 ,现在的解决方案似乎是编辑或创建~/.jupyter/custom/custom.js ,并添加线:

   Jupyter.notebook.set_autosave_interval(0); // disable autosave

This works for me. 这对我有用。 You can confirm if it works by looking for the brief "Autosave disabled" box in the top right corner of the Jupyter notebook on startup. 您可以通过在启动时在Jupyter笔记本右上角寻找简短的“禁用自动保存”框来确认它是否有效。 The full solution in the forum post did not work for me, probably because it is no longer completely valid, and errors in the custom.js file seem to occur silently. 论坛帖子中的完整解决方案对我不起作用,可能是因为它不再完全有效,并且custom.js文件中的错误似乎无声地发生。

Step-by-Step solution for Jupyter Notebook 5.5.0 on Windows (will probably work for other envs/versions as well) Windows上的Jupyter Notebook 5.5.0的分步解决方案(可能也适用于其他环境/版本)

  1. Find the Jupyter configuration folder: 找到Jupyter配置文件夹:

     from jupyter_core.paths import jupyter_config_dir jupyter_dir = jupyter_config_dir() # C:\\users\\<user_name>\\.jupyter on my machine 
  2. create sub-folder custom , and create file custom.js within it: 创建子文件夹custom ,并在其中创建文件custom.js

     ie 'C:\\users\\<user_name>\\.jupyter\\custom\\custom.js' 
  3. Put the following line in custom.js: 将以下行放入custom.js中:

     IPython.notebook.set_autosave_interval(0); 
  4. Save file and restart the Jupyter Notebook server (main app). 保存文件并重新启动Jupyter Notebook服务器(主应用程序)。

  5. When opening a notebook you should see "Autosave disabled" briefly appearing in the right side of the menu bar: 打开笔记本时,菜单栏的右侧会短暂显示“禁用自动保存”:

Autosave_Disabled

As of Jupyter 4.4 (2019), a working solution is to add this to your custom.js file: 从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.");
});

Without the require block the javascript will execute prior to the Jupyter object being available, resulting in an error. 没有require块,JavaScript将在Jupyter对象可用之前执行,从而导致错误。

Just to be clear, custom.js should reside at ~/.jupyter/custom/custom.js -- you must create the custom directory if it does not exist. 为了清楚起见,custom.js应该驻留在〜/ .jupyter / custom / custom.js中-如果custom目录不存在,则必须创建它。

Edit : The autosave interval on notebook load does not appear to work any more in recent version of Jupyter Notebook ( jupyter notebook --version at 6.0.1 ). 编辑 :在笔记本加载的自动保存间隔在Jupyter Notebook的最新版本( jupyter notebook --version6.0.1 )中jupyter notebook --version So I'm back to the custom.js solution: 所以我回到custom.js解决方案:

mkdir -p ~/.jupyter/custom
echo "Jupyter.notebook.set_autosave_interval(0);" >> ~/.jupyter/custom/custom.js

As pointed out by Thomas Maloney above, JupyterLab now has a command for that (Uncheck Autosave Documents in the Settings menu). 正如上面的Thomas Maloney所指出的,JupyterLab现在有一个命令(在“ 设置”菜单中取消选中“ 自动保存文档 )。

In Jupyter Notebook, I think the autosavetime extension is easier to use than the custom.js file. 在Jupyter笔记本电脑,我觉得autosavetime扩展相比,更便于使用custom.js文件。 The autosavetime extension is part of the Jupyter notebook extensions and can be installed with autosavetime扩展的一部分Jupyter笔记本扩展 ,可与安装

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install
jupyter nbextension enable autosavetime/main

Once it is installed, restart jupyter notebook and go to nbextensions_config in the Edit menu. 安装完成后,重新启动jupyter notebook然后转到“ 编辑”菜单中的nbextensions_config Select the autosavetime extension, and turn off autosave as follows: 选择autosavetime扩展,然后关闭自动保存,如下所示:

  • check the box Set an autosave interval on notebook load. 选中复选框设置笔记本计算机负载的自动保存间隔。 If false, the default is unchanged. 如果为false,则默认值保持不变。 ,
  • enter 0 for Autosave interval (in minutes) which would be set on notebook load . 输入0作为自动保存间隔(以分钟为单位),该间隔将在笔记本计算机上设置

To test the modification: open or create a Python notebook and execute, in a new cell, 要测试修改,请执行以下操作:打开或创建Python笔记本,然后在新单元格中执行,

%%javascript
element.text(Jupyter.notebook.autosave_interval);

If the result is 0, you have successfully turned the autosave off. 如果结果为0,则表示您已成功关闭自动保存功能。 Congratulations! 恭喜你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM