1

I am currently using Python 3.7.

My project has the following structure:

runner.py
    pkg1/
        __init__.py (empty)
        mod1.py
        mod1_helpers.py

In mod1.py:

import mod1_helpers

# call some functions in mod1_helpers.py

In runner.py:

import pkg1.mod1

When I run runner.py, Python threw the following error:

File "..\pkg1\mod1.py", line 1, in <module>  
    import mod1_helpers  
ModuleNotFoundError: No module named 'mod1_helpers'

The issue resolves when I manually add the path to pkg1 to sys.path in runner.py.

Could someone please advise the proper way to resolve this issue?

Chengs
  • 13
  • 3
  • Does this answer your question? [Changes in import statement python3](https://stackoverflow.com/questions/12172791/changes-in-import-statement-python3) – zvone Jan 13 '20 at 01:27

1 Answers1

0

Since they're in the same directory you have to prefix import of mod1_helpers with a .

try this:

import .mod1_helpers

bo2772
  • 1
  • 1