Id like the working directory of all notebooks to be the location where I run the command from, not the location the notebook is at.
As an example:
root_folder/
notebooks/
subject_A/
notebook.ipynb
src/
module.py
# notebook.ipynb
from src import module
I want to run jupyter notebook
(or lab) from root_folder
and import modules from the working directory. I dont consider os.chdir a good solution because moving the notebook to another folder will break the import. I'd also rather not add absolute paths inside the notebooks, this solution would not be exportable: my absolute path is not the same as yours.
I know I could add a setup.py
to make src
installable, but was looking for a more direct approach (I want to change the working directory, not install packages).
I also want an approach that is independent of the notebook location, it is the same regardless if it is at notebooks/A
or in notebook/A/B
.
Is there a way to do this?