I have seen several questions related to this error but I think they are different cases. My Django project has 2 applications and a directory structure like this and I'm facing an issue with relative imports I don't understand the logic.
Python allows me to import market
from file my_app2/signals.py
but it returns ValueError: attempted relative import beyond top-level package
if I import portfolio
from file my_app1/signals.py
. What is the reason and how can I found a wordaround?
/my_project
/my_project
__init__.py
/my_app1
market.py
signals.py # Here I can't import portfolio.py
/my_app2
portfolio.py
signals.py # Here I can import market.py
my_app1/signals.py
from ..my_app2 import portfolio # doesn't work
ValueError: attempted relative import beyond top-level package
from my_project.my_app2 import portfolio # doesn't work
ModuleNotFoundError: No module named 'my_project.my_app2'
my_app2/signals.py
from ..my_app1 import market # works