I have the following project architecture (simplified):
root/
main.py
mypackage/
__init__.py
module1.py
module2.py
ci_scripts/
script1.py
script2.py
doc/
doc
where the root is nothing more than a folder.
How do I import module1 and module2 in script1.py for example?
I tried to:
- Add the relative path inside script1.py:
from ..mypackage import module1
- The absolute path
- Use of sys package to append the path of
mypackage
To give more context, I was expecting that the following code inside of script1.py would work:
from ..mypackage import module1
module1.func1()
but I get:
ImportError: attempted relative import with no known parent package
And when I try to use the absolute path:
import mypackage.module1
module1.func1()
I get the following error:
ModuleNotFoundError: No module named 'mypackage'