For example I have this package:
└── package
│ __init__.py
│ first.py
│ second.py
and in my first.py
#first.py
def foo(): pass
in second.py
#second.py
from .first import foo
if __name__=='__main__':
foo()
Now if i try to execute the second.py as:
$ cd package
$ python3 second.py
I got this error:
ModuleNotFoundError: No module named '__main__.first'; '__main__' is not a package
why does this happen?
1 Answer 1
You should add first.py to second.py without dot
#second.py
from . import first
if __name__=='__main__':
first.foo()
answered Aug 5, 2018 at 4:15
Ali
2,6013 gold badges19 silver badges32 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py