0

I am having an issue importing a file that imports other files. My folder structure looks as follows:

Folder Structure:

proj/
    src/
        main_script.py
        some_module/
            module-file.py
            helper_a.py
            helper_b.py
            helper_c.py

Each of the files contain this

proj/src/main_script.py:

import module_file as mf

proj/src/some_module/module_file.py:

import helper_a
import helper_b
import helper_c

When I run main_script.py, the import of module_file.py fails with the following error:

ModuleNotFoundError: No module named 'helper_a'

If I were to set some_module as my working directory, this wouldn't be an issue, but the relative paths aren't working from the src directory. I tried adding a __init__.py file to the some_module folder, but that didn't affect the outcome. Any insight on how this is supposed to work would be appreciated.

teepee
  • 2,620
  • 2
  • 22
  • 47

1 Answers1

0

main_script.py

from some_module.module_file import * as mf

main_file.py

from helper_a import *
from helper_b import *
from helper_c import *
Lambo
  • 1,094
  • 11
  • 18
  • You must convert the hyphens to underscore as mentioned by Diego Torres Milano in the above comment – Lambo Jan 30 '20 at 06:07
  • Sorry I meant to use those as place holder. I run into this error without hyphens – teepee Jan 30 '20 at 06:19