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.
问题:
回答1:
If you add this to your custom.js
, it will disable autosave for all notebooks:
$([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
. 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.
回答2:
This will disable autosave once you're in IPython Notebook in the browser: %autosave 0
.
Update: There is now a UI feature in JupyterLab: https://github.com/jupyterlab/jupyterlab/pull/3734
回答3:
The original solution from MinRK is outdated, partly because IPython/Jupyter keeps changing so much. 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.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. 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.
回答4:
Step-by-Step solution for Jupyter Notebook 5.5.0 on Windows (will probably work for other envs/versions as well)
Find the Jupyter configuration folder:
from jupyter_core.paths import jupyter_config_dir jupyter_dir = jupyter_config_dir() # C:\users\<user_name>\.jupyter on my machine
create sub-folder
custom
, and create filecustom.js
within it:i.e. 'C:\users\<user_name>\.jupyter\custom\custom.js'
Put the following line in custom.js:
IPython.notebook.set_autosave_interval(0);
Save file and restart the Jupyter Notebook server (main app).
When opening a notebook you should see "Autosave disabled" briefly appearing in the right side of the menu bar:
回答5:
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
). So I'm back to the custom.js
solution:
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).
In Jupyter Notebook, I think the autosavetime
extension is easier to use than the custom.js
file. The autosavetime
extension is part of the Jupyter notebook extensions and can be installed with
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. Select the autosavetime
extension, and turn off autosave as follows:
- check the box Set an autosave interval on notebook load. If false, the default is unchanged.,
- enter 0 for Autosave interval (in minutes) which would be set on notebook load.
To test the modification: open or create a Python notebook and execute, in a new cell,
%%javascript
element.text(Jupyter.notebook.autosave_interval);
If the result is 0, you have successfully turned the autosave off. Congratulations!
回答6:
As of Jupyter 4.4 (2019), a working solution is to add this to your custom.js file:
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.
Just to be clear, custom.js should reside at ~/.jupyter/custom/custom.js -- you must create the custom
directory if it does not exist.