Likely this is a banal question, and I ardently hope for it to be so, but I have been stuck on it for too many days not to try asking for help for it.
There are similar questions in StackOverflow, for instance Python sub package imports and Python: importing a sub‑package or sub‑module. Still, these questions are relative to importing sub-packages (and their content) that actually are present within the package.
I have developed a few packages, let's call them package1
and package2
. These packages make sense on their own, have very complex dependencies and require some parts to be compiled, but once they are on Pipy, that complexity is removed from the end-user.
I am now working on a third package, package3
, which is meant to incorporate package1
and package2
and add some extra features. I want the user to import features from the package1
and package2
from package3
.
Stripping package3
to a skeleton, we can reduce it to a single __init__
file like the following:
// Content of the init file
import package1
import package2
__all__ = [
"package1",
"package2"
]
Now, when in a script, I do the following:
from package3 import package1
from package3 import package2
It works.
It does not work, though, to execute the following:
from package3.package1 import content_of_package1
as it raises the following error:
ModuleNotFoundError: No module named 'package3.package1'
But if I run the following it works:
import package3
import package1
assert dir(package1) == dit(package3.package1)
I have no clue to what try next unless I just mirror the entire package1
and package2
structure in package3
. Any suggestions to solve the ModuleNotFoundError
error?
Thank you.