Autonachlademode von Modulen in IPython [Duplikat]
-
19-09-2019 - |
Frage
Diese Frage bereits eine Antwort hier:
- Nachladen Submodule in IPython 11 Antworten
Gibt es eine Möglichkeit IPython automatisch alle geänderten Code nachladen zu müssen? Entweder vor jeder Zeile ist in der Schale ausgeführt oder andernfalls, wenn es um speziell angefordert wird. Ich habe viel von Sondierungs Programmierung zu tun mit IPython und SciPy und es ist ein ziemlich Schmerzen müssen manuell jedes Modul neu zu laden, wenn ich es ändern.
Lösung
Für IPython Version 3.1, 4.x und 5.x
%load_ext autoreload
%autoreload 2
Dann wird Ihr Modul sein Auto-Reloaded in der Standardeinstellung. Dies ist die doc:
File: ...my/python/path/lib/python2.7/site-packages/IPython/extensions/autoreload.py
Docstring:
``autoreload`` is an IPython extension that reloads modules
automatically before executing the line of code typed.
This makes for example the following workflow possible:
.. sourcecode:: ipython
In [1]: %load_ext autoreload
In [2]: %autoreload 2
In [3]: from foo import some_function
In [4]: some_function()
Out[4]: 42
In [5]: # open foo.py in an editor and change some_function to return 43
In [6]: some_function()
Out[6]: 43
The module was reloaded without reloading it explicitly, and the
object imported with ``from foo import ...`` was also updated.
Es gibt einen Trick: Wenn Sie vergessen alle der oben als ipython
verwenden, nur versuchen:
import autoreload
?autoreload
# Then you get all the above
Andere Tipps
Wie bereits erwähnt, müssen Sie die autoreload
Erweiterung. Wenn Sie es wollen, jedes Mal automatisch starten Sie ipython
starten, müssen Sie es auf die ipython_config.py
Startdatei hinzuzufügen:
Es kann notwendig sein, einen zu erzeugen zuerst:
ipython profile create
sind dann diese Zeilen in ~/.ipython/profile_default/ipython_config.py
:
c.InteractiveShellApp.exec_lines = []
c.InteractiveShellApp.exec_lines.append('%load_ext autoreload')
c.InteractiveShellApp.exec_lines.append('%autoreload 2')
Neben eine optionale Warnung des Falles, dass Sie die Vorteile des kompilierten Python-Code in .pyc
Dateien zu übernehmen:
c.InteractiveShellApp.exec_lines.append('print "Warning: disable autoreload in ipython_config.py to improve performance." ')
edit: die oben genannten Arbeiten mit Version 0.12.1 und 0.13
REVISED -. Siehe Andrew_1510 beantworten unten, wie IPython aktualisiert wurde
...
Es war ein bisschen schwierig, herauszufinden, wie man dorthin kommt aus einem staubigen Bug-Report, aber:
Es wird mit IPython jetzt!
import ipy_autoreload
%autoreload 2
%aimport your_mod
# %autoreload? for help
... dann jedes Mal, wenn your_mod.dwim()
nennt, wird es die neueste Version holen.
Wenn Sie fügen ipython_config.py in ~ / .ipython / profile_default dir mit folgenden Zeilen mag dann Autonachlademode Funktionalität auf ipython Start geladen werden (getestet auf 2.0.0):
print "--------->>>>>>>> ENABLE AUTORELOAD <<<<<<<<<------------"
c = get_config()
c.InteractiveShellApp.exec_lines = []
c.InteractiveShellApp.exec_lines.append('%load_ext autoreload')
c.InteractiveShellApp.exec_lines.append('%autoreload 2')
Sie können mit:
import ipy_autoreload
%autoreload 2
%aimport your_mod
Es ist eine Erweiterung für das, aber ich habe keine Verwendung Erfahrung noch:
http://ipython.scipy.org/ipython /ipython/attachment/ticket/154/ipy_autoreload.py