My directory structure is as follows.
project/
jupyter/
note.ipynb
src/
some_script.py
another_script.py
The jupyter
subdirectory contains Jupyter notebooks and the src
subdirectory contains my .py
files. The src
subdirectory is marked as the sources root.
In the Jupyter notebook note.ipynb
, if I do import some_script
, then I get ImportError: No module named 'some_script'
. However, from src import some_script
works fine, but not if some_script
also has a line import another_script
. In my mind I'm thinking that there is a setting or switch somewhere that adds the src
subdirectory to the PYTHONPATH
used by the Jupyter Notebook environment by default, but I don't know how to do it, could you help?
I know that I can always use sys.path.append
but I don't want to do that in every single Jupyter notebook I create. I know also that I can just put the .ipynb
files and .py
files in the same subdirectory but I don't like organising my work that way. Finally, I know I can just set the project directory as my sources root instead of the src
subdirectory, but that would mean that I'd have to do from src import ...
everywhere in my .py
scripts, and obviously I don't want to do that. Is there a solution to this problem as I've described above?