Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear cached images in Jupyter Notebook

I have a jupyter notebook that creates a local cache of images. I would like to clear the cache before I run a particular cell. Does anyone know how to do that? I tried:

import gc
gc.collect()

But it had no effect. I also tried clear all the cookies and cache in chrome, but that did work either.

like image 624
user3476463 Avatar asked Mar 30 '18 03:03

user3476463


People also ask

How do you clear the cache on a Jupyter notebook?

When you have Jupyter notebook opened, you can do this by selecting the Cell -> All Output -> Clear menu item.

How do I clean my Jupyter notebook?

Press 'control-shift-p', that opens the command palette. Then type 'clear cell output'. That will let you select the command to clear the output.

Does Jupyter notebook cache?

Jupyter Book can automatically run and cache any notebook pages. Notebooks can either be run each time the documentation is built, or cached locally so that notebooks will only be re-run when the code cells in a notebook have changed.

How do I clear data cache in python?

After the use of the cache, cache_clear() can be used for clearing or invalidating the cache. These methods have limitations as they are individualized, and the cache_clear() function must be typed out for each and every LRU Cache utilizing the function.


Video Answer


2 Answers

Try the following in a new cell of your Jupyter Notebook:

%reset -f

The above will clear all variables without User Confirmation. If you want explicit user confirmation, just drop the -f.

%reset_selective -f varName

The above will delete particular variable.


In case the Python version you are using is greater than 3.3, you may also try (I haven't used it!):

%store -d someVar  # Remove particular variable and its value from storage

%store -z          # Remove all variables from storage

For more info, check this doc.

like image 126
anurag Avatar answered Sep 29 '22 19:09

anurag


I realise this isn't a great (bordering on terrible) answer - in short, close and re-open the browser.

I've been struggling with this myself today, and even clearing the browser cache did not seem to work. The only way I've found refresh images is to:

  1. Save your notebook
  2. Halt and close the session
  3. Close the browser
  4. When you re-open the notebook - the new images will appear

... I even tried deleting the referenced image file. But the browser still held onto it.

like image 31
S3DEV Avatar answered Sep 29 '22 19:09

S3DEV