How to pickle or store Jupyter (IPython) notebook session for later
Let's say I am doing a larger data analysis in Jupyter/Ipython notebook with lots of time consuming computations done. Then, for some reason, I have to shut down the jupyter local server I, but I would like to return to doing the analysis later, without having to go through all the time-consuming computations again.
What I would
like love to do is
pickle or store the whole Jupyter session (all pandas dataframes, np.arrays, variables, ...) so I can safely shut down the server knowing I can return to my session in exactly the same state as before.
Is it even technically possible? Is there a built-in functionality I overlooked?
#inside a ipython/nb session
foo = "A dummy string"
closing seesion, restarting kernel
%store -r foo # r for refresh
print(foo) # "A dummy string"
which is fairly close to what I would want, but having to do it manually and being unable to distinguish between different sessions makes it less useful.
I think Dill answers your question well.
pip install dill
Save a Notebook session:
import dill dill.dump_session('notebook_env.db')
Restore a Notebook session:
import dill dill.load_session('notebook_env.db')
★ Back to homepage or read more recommendations: