파이썬을 사용하다보면 불편해질때가 있다. 스크립트 코드를 바꾸고 주피터 노트북에서 반영된 코드를 불러오기 위해선 restart 버튼을 눌러야하고 기존에 할당된 변수들이 다 사라지는 경험..
이럴 때 autoreload 설정을 해주면 restart를 해주지 않아도 주피터 노트북에서 반영된 코드를 바로 사용할 수 있다. 먼저 profile을 생성한다. 생성해줌과 동시에 파일 위치도 알려준다.
ipython profile create # 결과 [ProfileCreate] Generating default config file: PosixPath('/Users/username/.ipython/profile_default/ipython_config.py') [ProfileCreate] Generating default config file: PosixPath('/Users/username/.ipython/profile_default/ipython_kernel_config.py')
파일 위치 디렉토리로 옮긴 후 ipython_config.py를 vi로 열고 맨 마지막에 아래와 같이 추가해주면 된다. 이제 jupyter를 재실행해서 확인해보자!
c.InteractiveShellApp.exec_lines = [] c.InteractiveShellApp.exec_lines.append('%load_ext autoreload') c.InteractiveShellApp.exec_lines.append('%autoreload 2')