我的i
python_config.py中有以下内容:
print "Test autoreload" #confirm this gets loaded
c = get_config()
c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']
它似乎适用于正常的ipython会话:
$ipython
Test autoreload
In [1]: %autoreload 2
In [2]:
但是,当使用使用IPython.embed()的嵌入式shell脚本时,autoreload magic不再起作用.
例如,在shell.py中:
from IPython import embed
embed()
这仍然加载我的ipython_config.py,正如“测试自动加载”打印出来的那样,但是自动加载扩展没有加载(没有%autoreload magic):
$python shell.py
Test autoreload
In [1]: %autoreload 2
ERROR: Line magic function `%autoreload` not found.
最佳答案 据我所知,这是一个
(known)错误.只有在有应用程序的情况下才会加载扩展,因此在使用嵌入时,它不会被加载(尽管读取了配置).
github上有一个open issue来解决这个问题,但它从未实现过.