I'm running a script in ipython via the run magic:
%run myscript.py
and this script imports various modules that I've written, and which I often change between runs. I want to automatically reload these modules, rather than having to restart ipython. There are lots of questions on stackoverflow and elsewhere that recommend
%load_ext autoreload
%autoreload 2
and maybe also
%aimport <your module>
thrown in for good measure. But this simply doesn't work. Is a deep reload beyond what autoreload is capable of doing? Is there perhaps some other way of removing all loaded modules, or silently restart the python background process that ipython relies on?
EDIT: having played around with this a bit more, it seems that the autoreload failure is a little more subtle. It may be (I'm not 100% certain yet) that autoreload only fails when my module's __init__.py is doing from .<some file in the module> import *
, rather than importing each member by name. I have also tried the %reset
magic, but this only appears to empty the namespace, it doesn't clear the cached modules.
As an aside, Spyder is able to force reloading of modules, but I'm not sure how this is done (some kind of wrapper around ipython which restarts the process?)