Weird behaviour of python with module import

When having a project tree like this one

/
└──  weird_bug
   ├──  main.py
   └──  model
      ├──  directions.py
      └──  weirdo.py

and with this code in the specific classes:

main.py:

from model.directions import Direction
from model.weirdo import Weirdo

def print_direction():
    player = Weirdo(Direction.up)
    player.print_direction()
if __name__ == '__main__':
    print_direction()

directions.py:

from enum import Enum

class Direction(Enum):
    up, down = range(2)

and finally weirdo.py:

from directions import Direction

class Weirdo:
    def __init__(self, direction):
        self.direction = direction
    def print_direction(self):
        if self.direction == Direction.up:
            print(self.direction)

I am receiving this error when I am calling main.py:

ModuleNotFoundError: No module named 'directions'

The error is triggered by the weirdo.py class. I am trying imports around for literally hours and was wondering if someone knows what is happening and can help me understand. Thanks!


When running main.py as an entrypoint, absolute path to directions is model.directions, and that is what needs to be in defined in the weirdo file import.

If you want to avoid specifying full path, you can use relative import in the form of from .directions import Direction in weirdo.py