Reputation: 563
I made the following architecture:
parent/
main.py
tool/
__init__.py
base.py
view.py
base.py
and view.py
hosts the classes of the same name.
__init__.py
from .base import Base
from .view import View
view.py
from .base import Base
main.py
from tool import View
When I execute directly main.py
its works fine.
But when I execute only view.py
with python tool/view.py
I got the error:
from .base import Base
ImportError: attempted relative import with no known parent package
So if I change from .base import Base
to from base import Base
in view.py
, python tool/view.py
works but python main.py
fails with:
from base import Base
ModuleNotFoundError: No module named 'base'
What import should be made to make both work?
python main.py
and
python tool/view.py
Thanks for your help.
Upvotes: 1
Views: 141
Reputation: 11486
Your first imports are fine, you should just change the second command to
python -m tool.view
Upvotes: 2