Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to disable saving to checkpoints for Jupyter Notebooks?

I am working in an environment where writing to the disk space with a folder name like .ipynb_checkpoints is disallowed.

Unfortunately, this is Jupyter Notebook's default path for Save and Checkpoint. Is there a way to configure Jupyter Notebook to not use the checkpoint feature or allow a different folder name?

like image 898
JoT Avatar asked Aug 17 '18 02:08

JoT


People also ask

Where are Jupyter Notebook checkpoints stored?

As a side note, the checkpoint file is located within a hidden folder named . ipynb_checkpoints . This folder is located within the same folder as the initial . ipynb file.

Are Jupyter notebooks automatically saved?

Jupyter Notebooks autosave, so you don't have to worry about losing code too much. At the top of the page you can usually see the current save status: Last Checkpoint: 2 minutes ago (unsaved changes)

Is it safe to delete Ipynb checkpoints?

The checkpoints are only updated on a manual save, whereas the main copy of the file is updated both on manual saves and on autosaves. The idea is that if you accidentally delete something just before it autosaves, you have the checkpoint to go back to.

Where do Jupyter notebooks save?

On Linux and other free desktop platforms, these runtime files are stored in $XDG_RUNTIME_DIR/jupyter by default. On other platforms, it's a runtime/ subdirectory of the user's data directory (second row of the table above).


3 Answers

Not exactly an answer to your question, but perhaps close enough.

The path of the checkpoints folder is configurable so you could rename it to something allowed such as "_ipynb_checkpoints", or you could move it to a completely different folder.

You simply have to add

c.FileCheckpoints.checkpoint_dir = '_ipynb_checkpoints'

to jupyter_notebook_config.py

like image 194
davost Avatar answered Oct 12 '22 21:10

davost


There are couple of ways to stop autosaves.

There is a contrib nbextension called AutoSaveTime if you have installed jupyter-contrib-nbextensions that adds an autosave time configuration on the toolbar of a notebook, just ensure:

"autosavetime/main": true

is set in your notebook.json configuration file.

Alternatively in a Cell, to change the autosave value for the current notebook, you can write:

%autosave 0

Or you can change your custom.js to make this permanent for all notebooks:

define([
    'base/js/namespace',
    'base/js/events'
    ],
    function(IPython, events) {
        events.on("notebook_loaded.Notebook",
            function () {
                IPython.notebook.set_autosave_interval(0);
            }
        );
    }
);
like image 24
AChampion Avatar answered Oct 12 '22 20:10

AChampion


You can uncheck Settings -> AutosaveDocuments to avoid autosave file, but it always create .ipynb_checkpoints folder when you open a file, I can not find a solution to avoid this behavior,there is a way that you can specify a folder to collect all the checkpoint files and delete them together.

  1. In jupyterlab, you can use jupyter notebook --generate-config to generate a config file named jupyter_notebook_config.py .
  2. Then you can edit this file: c.FileContentsManager.checkpoints_kwargs = {'root_dir': r'D:\'} .

Or you can just use cammand line option

jupyter lab --FileContentsManager.checkpoints_kwargs="root_dir"="D:/"
like image 1
HH0714 Avatar answered Oct 12 '22 21:10

HH0714