Suppose we have the following project structure:
E:\demo_proj\
utilities_package\
__init__.py
util_one.py
util_two.py
demo_package\
__init__.py
demo_sub_package\
__init__.py
demo_sub_sub_package\
demo_file.py
What is a sensible way for demo_file.py
to import from utilities_package
?
The utilities_package
is in a much higher level directory than demo_file.py
.
Although it is not shown in the little diagram I gave above, suppose that utilities_package
is used everywhere throughout the project. It is not sensible to make utilities_package
a sub-directory of demo_sub_sub_package
Some similar questions have been asked here and here.
The asker of the first question neglected to include a __init__.py
in their packages. That is not an issue in my case.
The answers given to the the second question linked-to above are problematic:
- Most of the answers are quite old. For example,
Loader.load_module
was deprecated after Python 3.4 - Most of the answers are specific to the question in that they only go up one directory, whereas, I would like to go up several levels.
- Some of the answers are high-level descriptions without code. Other answers have the opposite problem: they contain ugly-looking code, but don't bother to explain it.
I am open to solutions which require restructuring the project. I'm also interested in solutions which leave the project structure intact, but which insert the relevant code into demo_file.py