This website www.ds4n6.io uses its own and third party cookies to collect information that helps to optimize your visit to their web pages. Cookies will not be used to collect personal information. You can either allow or reject their use. You can also change their settings at any time. You will find more information on our Cookie Policy page.

OK

DS4N6 Knowledge >> Tips & Tricks >> Saving/Restoring a Jupyter Notebook Session

Saving/Restoring a Jupyter Notebook Session

Say you have been working a lot in your current notebook, you have lots of DataFrames and Series that get a long time to be computed, and you want to make sure you recover quickly if, for some reason, your Session (Kernel) dies.

The answer is “dill”.

Installation:

    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')

Caveats:

  • Fails when there are generators.
  • If you have pyodbc connection objects hanging around, you'll need to close them and then set them all to None otherwise, you get a “TypeError: can't pickle pyodbc.Connection objects” error.
  • The notebook state does not include graphs that were generated by your code, so you'll need to rerun the cells to bring these back.

Refs: