How do I get IPython autoreload magic to load automatcially when using an embedded shell?

ipython, python

Solution

As far as I can tell, this is a (known) bug. Extensions are only loaded if there is an Application, so when using embed, it won't get loaded (although the config is read).

There is an open issue on github to fix this, but it has never been implemented.

Problem

I have the following in my `ipython_config.py`: ``` print "Test autoreload" #confirm this gets loaded c = get_config() c.InteractiveShellApp.extensions = ['autoreload'] c.InteractiveShellApp.exec_lines = ['%autoreload 2'] ``` And it seems to work for normal ipython sessions: ``` $ ipython Test autoreload In [1]: %autoreload 2 In [2]: ``` However, when using an embedded shell script that uses IPython.embed(), the autoreload magic no longer works. For example, in `shell.py`: ``` from IPython import embed embed() ``` This still loads my ipython_config.py, as evidenced by `"Test autoreload"` printing out, however the autoreload extension does not get loaded (no %autoreload magic): ``` $ python shell.py Test autoreload In [1]: %autoreload 2 ERROR: Line magic function `%autoreload` not found. ```

Original source