Setup
test/
main.py
pkg/
a.py
__init__.py
main.py
contains:
import pkg
pkg.a
__init__.py
contains:
from . import a
main.py
can be run without errors.
Question
Changing the content of __init__.py
to
import a
gives the following error when running main.py
:
Traceback (most recent call last):
File "C:/Users/me/PycharmProjects/test/main.py", line 1, in <module>
import pkg
File "C:\Users\me\PycharmProjects\test\pkg\__init__.py", line 1, in <module>
import a
ModuleNotFoundError: No module named 'a'
Interestingly, __init__.py
can be executed directly with python __init__.py
without errors.
What's going on?