I have been editing a Jupyter Notebook for the past week, and tried saving it today. While attempting to save it, I got an error, so I refreshed the page and successfully saved it.
However, to my dismay almost all of my command history was lost! I still have access to the variables (the kernel never died), but I don't have access to any of the code.
Is there any way to recover the code? The kernel is still running, but I do not see any checkpoints in my notebook.
You can get the IPython history, which Jupyter Notebook uses as its kernel. In one of the cells run:
%history
This will dump a history (good, bad, and ugly) of every command you have run in the current IPython session. It is probably more than you want, but it is better than losing all your work.
Something similar happened to me where I could not save what I did, refreshed the page, and lost all my commands.
You can get your entire notebook history and redirect the output to any given file by running
%history -g -f filename
In my case, I redirected it to a (.py) file. You can find more documentation here https://ipython.readthedocs.io/en/stable/interactive/magics.html under "%history".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With