My project directory has this structure:
src
|__model
|___models.py
|___ prepare_data.py
|_utils.py
models.py imports a function from prepare_data.py, which imports a function from utils.py.
When I run the script from bash, if I'm in the model folder the command is:
python models.py and I get the error:
ModuleNotFoundError: No module named 'utils'
If instead I run the command from the src folder with python model/models.py the error I get is
ModuleNotFoundError: No module named 'prepare_data'
I know that moving utils.py in the model directory would fix the problem but I don't want to do that. I tried using the -m argument with dotted notation. So the second command becomes:
python -m model.models, but I still get the same error. What can I do to fix it?
EDIT: I also tried putting an empty __init__.py file in the root directory but it didn't fix the problem
EDIT 2: I solved the problem by typing this at the beginning of the
model.py module, as suggested in this answer:
import sys
sys.path.append('../')