'Module not found error although __init__.py file is in every folder. What is missing?

I have a project that has several folders inside the project folder where classes were defined. Folder structure is as follows :

--> model (folder)
    - model1 (file)
    - model2 (file)
--> setup (folder)
    --  __init__.py (file)
    --  load_model.py
    --> utils (folder)
        -- __init__.py (file)
        -- utilities.py (file)
--  setup.py (file)
--  __init__.py (file)
--  inference.py (file)

load_model.py is as follows --> (few lines)

from utils.utilities import *
import cv2

inference.py file is as follows (few lines)

from setup.load_model import *

When I run 'inference.py', I get the error that

No module named 'utils' 

at from utils.utilities import * line in utilities.py file.

Although I have included init.py (empty) in each folder, the system does not recognize utils as the folder located in the setup file.

Any help with this error ? (If I keep the utils folder in root, this works fine anyway)



Solution 1:[1]

Not sure why, but updating the following line

from utils.utilities import *

to

from .utils.utilities import * 

fixed the issue. There is a '.' at the beginning of the 'utils'.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PCG