Python – Import file inside folder – No module found

  python, python-import

Here is my file structure:

DoSomething.py
Helpers
   |------TextHelper.py
   |------MyConstants.py

Helpers folder contains 2 files – TextHelper.py and MyConstants.py. The TextHelper file contains methods that are used by DoSomething. The methods in TextHelper use the constants in the MyConstants file. The DoSomething file does not use the constants directly. Here are the import statements:

DoSomething.py

from Helpers import TextHelper

TextHelper.py

import MyConstants

Here is the entire MyConstants.py file

some_constant_1 = ""
some_constant_2 = 20

When I run DoSomething file, I get error:

Traceback (most recent call last):
  File "C:<path>DoSomething .py", line 10, in <module>
    from Helpers import TextHelper
  File "C:<path>HelpersTextHelper.py", line 5, in <module>
    import MyConstants
ModuleNotFoundError: No module named 'MyConstants'

What am I doing wrong?

Source: Python Questions

LEAVE A COMMENT