Imports in nested notebooks

Suppose I have the following folder structure in my notebook’s directory:


  • submodule/
    ---- funcA.ipynb
    ---- funcB.ipynb
  • func1.ipynb
  • func2.ipynb
  • lib_name(sym_link)

The instruction recursive=True is correctly creating the module structure for the .py files. When I import func1 from func2:

from lib_name import func2. 

it works because there is the lib_name folder.
Suppose that I import funcA from funcB:

from lib_name.submodule import funcA. 

this would not work unless I create a new symbolic link in the submodule folder.
Is there a way to automate this?
Or what strategy would work the best with nested notebooks and their corresponding .py modules?

In every notebook before the imports, I added:

import sys

and it seems to be working

1 Like