This has been asked before, but none of the solutions are yielding any results. I have a parent directory with
parent/
__init__.py
database.py
collect/
__init__.py
collect.py
I would like to import database.py
from collect.py
but I constantly get ValueError: Attempted relative import in non-package
. Currently in collect.py
I am just doing
import sys
sys.path.append("..")
import database
which does not feel very pythonic. I would like to have something like
from .. import database
Yet I always get that ValueError
. Any help is appreciated. What exactly is causing this error. I thought adding __init__.py
would fix the issue, but it changed nothing. Also, is there anything wrong with my current fix? It doesn't feel like the best solution to me.
Edit: I should add that I cannot successfully import from ipython running in collect/
either, if that affects anything.