IPYTHON의 모듈 자동으로 [복제
-
19-09-2019 - |
문제
이 질문은 이미 여기에 답이 있습니다.
- IPYTHON의 하위 모듈 새로 고침 11 답변
IPYTHON이 변경된 모든 코드를 자동으로 다시로드 할 수있는 방법이 있습니까? 각 라인이 쉘에서 실행되기 전에 또는 구체적으로 요청 될 때 실패하기 전에. 나는 ipython과 scipy를 사용하여 많은 탐색 프로그램을하고 있으며 변경할 때마다 각 모듈을 수동으로 다시로드 해야하는 것은 상당히 고통 스럽습니다.
해결책
IPYTHON 버전 3.1, 4.X 및 5.X의 경우
%load_ext autoreload
%autoreload 2
그러면 모듈이 될 것입니다 자동으로로드 기본적으로. 이것은 문서입니다.
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.
속임수가 있습니다 : 당신이 모두 잊어 버리세요 사용시 위의 ipython
, 단지 시도:
import autoreload
?autoreload
# Then you get all the above
다른 팁
위에서 언급했듯이, 당신은 필요합니다 autoreload
확대. 출시 할 때마다 자동으로 시작하려면 ipython
, 당신은 그것을 추가해야합니다 ipython_config.py
시작 파일 :
먼저 하나를 생성해야 할 수도 있습니다.
ipython profile create
그런 다음이 라인을 포함시킵니다 ~/.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')
컴파일 된 Python 코드를 활용 해야하는 경우 선택적 경고뿐만 아니라 .pyc
파일 :
c.InteractiveShellApp.exec_lines.append('print "Warning: disable autoreload in ipython_config.py to improve performance." ')
편집 : 위의 버전은 0.12.1 및 0.13 버전으로 작동합니다.
개정 - Andrew_1510을 참조하십시오 대답 아래에서 ipython이 업데이트되었으므로 아래에서.
...
먼지가 많은 버그 보고서에서 도착하는 방법을 조금 어렵게 만들었습니다.
그것은 지금 Ipython과 함께 배송됩니다!
import ipy_autoreload
%autoreload 2
%aimport your_mod
# %autoreload? for help
... 그런 다음 전화 할 때마다 your_mod.dwim()
, 최신 버전을 선택합니다.
ipython_config.py를 ~/.ipython/profile_default에 아래와 같은 줄과 함께 추가하면 iPyThon 스타트 업에 자동 부로 기능이로드됩니다 (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')
당신이 사용할 수있는:
import ipy_autoreload
%autoreload 2
%aimport your_mod
그것에 대한 확장이 있지만 아직 사용 경험이 없습니다.
http://ipython.scipy.org/ipython/ipython/attachment/ticket/154/ipy_autoreload.py