2017년 8월 31일 목요일

shell_plus notebook settings Import error in subdirectory · Issue #865 · django-extensions/django-extensions

shell_plus notebook settings Import error in subdirectory · Issue #865 · django-extensions/django-extensions:



django-extensions 사용시 ipython 노트북 파일을 manage.py 파일이 위치하는 디렉토리의 서브디렉토리에 관리하고 싶을 때 문제를 겪다가 ... 해결방법을 찾음.





Project layout:
/project
    /someapp
    /notebooks
        ipython_config.py
    settings.py
settings.py
NOTEBOOK_ARGUMENTS = [
    '--notebook-dir', 'notebooks',
]

IPYTHON_ARGUMENTS = [
    '--debug',
]
notebooks/ipython_config.py
import sys
import os

FILE_PATH = os.path.abspath(os.path.dirname(__file__))
PROJECT_BASE_PATH = os.path.abspath(os.path.join(FILE_PATH, '..'))

# Allows the kernel to "see" the project during initialization. This
# FILE_PATH corresponds to Jupyter's "notebook-dir", but we want notebooks to
# behave as though they resided in the base directory to allow for clean
# imports.
print("sys.path BEFORE = {}".format(sys.path))
sys.path.insert(1, PROJECT_BASE_PATH)
print("sys.path AFTER = {}".format(sys.path))

# Any additional initialization logic goes here


'via Blog this'

댓글 없음:

댓글 쓰기