天天看點

default module reload for Jupyter Notebook

https://stackoverflow.com/a/5399339/8037585

IPython comes with some automatic reloading magic:

%load_ext autoreload

%autoreload 2

It will reload all changed modules every time before executing a new line. The way this works is slightly different than dreload. Some caveats apply, type %autoreload? to see what can go wrong.

If you want to always enable this settings, modify your IPython configuration file

~/.ipython/profile_default/ipython_config.py

[1] and appending:

c.InteractiveShellApp.extensions = [‘autoreload’]

c.InteractiveShellApp.exec_lines = [‘%autoreload 2’]

c.InteractiveShellApp.exec_lines.append(‘print(“[WARNING] disable autoreload in ipython_config.py to improve performance.”)’)

Credit to @Kos via a comment below.

[1] If you don’t have the file ~/.ipython/profile_default/ipython_config.py, you need to call ipython profile create first. Or the file may be located at $IPYTHONDIR.