manifoldai / docker-cookiecutter-data-science

A fork of the cookiecutter-data-science leveraging Docker for local development.
http://drivendata.github.io/cookiecutter-data-science/
MIT License
130 stars 29 forks source link

How to import Python code in src folders when using notebooks? #4

Open davidrpugh opened 6 years ago

davidrpugh commented 6 years ago

How do you import python modules defined in the src sub-directories when using Jupyter notebooks residing in the notebook directory?

davidrpugh commented 6 years ago

My current solution is to do the following in the notebooks...

import sys

sys.path.append("..")
from src.data import ???

...where ??? should be replaced by whatever scripts you are importing.

rkoppula commented 5 years ago

That's the solution we use as well. In next release we could add export PYTHONPATH="$PYTHONPATH:/mnt" as environment variable in the image.

davidrpugh commented 5 years ago

@rkoppula I think it might be better to explicitly document the need to import the scripts as above rather than append the PYTHONPATH variable in the Dockerfile. But perhaps the median user would prefer a solution that makes imports just work as expected.