Why is a Module Not found error happening despite having the init file?

I am using Spyder with Python 3.8 in Anaconda. I have files p,c,s,d and init in the same directory. I am posting the relevant lines.

File p:

from s import C

File s:

class S():
from d import D

File c:

from .s import S
class C(S):

File d:

class D()

init file:

from .s import S
from .c import C
from .d import D

File p is the main file here. When I run it, I get a module not found error. with the traceback being

from s import C (file P)
from .s import S (init)
class S() (file s)
from d import  D (file s)

ModuleNotFoundError: No module named d. Why is this happening? I am using a Mac.


If you have a package `mypackage┬┤,


and mypackage/__init__.py is

from .a import A
from .b import B

(but that doesn’t really matter here) then mypackage/b.py can import A via a relative import

from .a import A

or an absolute import

from mypackage.a import A

but not

from a import A