Python Cannot Import from the src/ Directory
07:51 05 Aug 2022

I have a project with this structure:

root-project/
    src/
        utils/
            file_check.py
        main.py
        type_aliases.py
    ...

In the src/utils/file_check.py I import something from src/type_aliases.py but I always get a ModuleNotFound exception. These are what I have tried:

from src.type_aliases import ...

I also removed the src.:

from type_aliases import ...

These are the exceptions:

ModuleNotFoundError: No module named 'src'

The second one:

ModuleNotFoundError: No module named 'type_aliases'

I ran the files through the root-project/ directory, however, I also switched to the src/ directory but I still got the exception.

I also checked the sys.path variable and added src/ directory but I still get the error:

import sys

sys.path.append("/home/eastern-skill7173/dev/python/root-project/src/")

from src.type_aliases import ...

Still the error is visible

python python-3.x python-import importerror modulenotfounderror