Ho un pacchetto padre con 2 pacchetti figlio. Sembra che questoImpossibile importare moduli di pacchetti parent all'interno di pacchetti figlio
backend
__init__.py
conf.py
db.py
connections.py
/api
__init__.py
register.py
api.py
/scheduled
__init__.py
helpers.py
All the __init__.py files are empty.
Il codice in backend/connections.py
e backend/conf.py
viene utilizzato dai moduli in entrambi i pacchetti api
e scheduled
.
in register.py ho codice come
from backend.conf import *
from backend.connections import *
Ora quando faccio python register.py
ottengo questo errore
ImportError: No module named backend.conf
Anche quando ho cambiato from backend.conf import *
a from ..conf import *
o from .. import conf
ottengo questo errore
ValueError: Attempted relative import in non-package
Quello che ho capito dall'errore sopra riportato è che Python non sta trattando le suddette cartelle come pacchetti. Ma ho __init__.py
in tutte le cartelle. Che c'è?
@MrE perché 'connections' non è un modulo? tutti i file '__init __. py' sono vuoti. – lovesh