Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

ipython

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.
like image 603
Ben Davis Avatar asked Aug 15 '13 17:08

Ben Davis


1 Answers

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.

like image 154
remram Avatar answered Oct 03 '22 23:10

remram