I often like to start my ipython session from where I last left off - similar to saving a firefox browsing session. IPython already automatically saves your input history so that you can look up commands in your history, but it doesn't save your variables. Here are the steps to save the state of your variables on exit and have them loaded on startup:
-
Add the save_user_variables.py script below to your ipython folder (by default $HOME/.ipython). This script takes care of saving user variables on exit.
-
Add this line to your profile's ipython startup script (e.g., $HOME/.ipython/profile_default/startup/startup.py):
get_ipython().ex("import save_user_variables;del save_user_variables")
-
In your ipython profile config file (by default $HOME/.ipython/profile_default/ipython_config.py) find the following line:
# c.StoreMagics.autorestore = False
Uncomment it and set it to true. This automatically reloads stored variables on startup. Alternatively you can use reload the last session manually us