Configure autoreload for IPython

— 1 minute read

IPython is truly wonderful for developing with Python. It comes with useful defaults, but one thing I was missing was autoreloading of modules. These answers on stackoverlflow include everything you need but the correct solution for newer versions of IPython (1.1.0 at the time of writing) isn't spelled out in one place, so I had to combine elements of several answers.

What I ended up doing was:

ipython profile create

Then edit ~/.config/ipython/profile_default/ and add:

c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']
c.InteractiveShellApp.exec_lines.append('print("Warning: disable autoreload in to improve performance.")')

You will now be able to load IPython, import a module and have it automatically reload when you make changes to it.