본문 바로가기

IT/Python

[Jupyter] 라이브러리/모듈 자동 재로드

매번 라이브러리나 모듈을 수정하면 jupyter에서는 import 된 상태로 그대로 있기 때문에 jupyter kernel 을 재시작해줘야하거나 별도로 reload를 해야한다.

 

매직라인으로 자동 리로드 할 수 있다.

%load_ext autoreload
%autoreload all

 

이렇게만 써놓으면 자동으로 항상 reload 한다 

 

%autoreload now: 현재 시점에서 재로드

%autoreload off: 끔

%autoreload explicit: %aimport가 있는 경우에만 재로드

%autoreload all: 항상 리로드

 

노트북 환경이랑 일반환경을 번갈아가면서 쓸 때에는.. 아래처럼

from IPython import get_ipython
if get_ipython():
	get_ipython().run_line_magic('load_ext', 'autoreload')
	get_ipython().run_line_magic('autoreload', 'all')