I've been looking for it already answer in stackoverflow, but i didn't find a solution.
I use the 3.6.2 version of python and I have a folder structure like this
backend
| __init__.py
|
|------- entity_extraction\
| __init__.py
| main.py
|------- index\
| __init__.py
| main.py
|------- lib\
| __init__.py
| |--- db\
| __init__.py
|------------ |--- models\
| __init__.py
| model.py
If I import model.py from main.py in the index folder in this way and run python main.py:
from backend.lib.db.models import *
I have this error:
Traceback (most recent call last):
File "main.py", line 5, in <module>
from backend.lib.db.models import *
ModuleNotFoundError: No module named 'backend'
How I import in absolute way a module that is in a folder outside the current run script folder? The only way that works is import sys and add the uplevel folder path, but seems an hack.
Thanks!