Comment déboguer Python échec d'importation

J'ai une structure de répertoire:

network/__init__.py
network/model.py
network/transformer/__init__.py
network/transformer/t_model.py

les deux __init__.py fichiers appropriés

__all__ = [
    "model",  # or "t_model" in the case of transformer
    "view",
    ]

Dans t_model.py, j'ai

from .. import model

mais il dit:

ImportError: cannot import name model

Si j'essaie

from ..model import Node

il dit:

ImportError: cannot import name Node

Ces sont très confus erreurs.


Edit: Même un absolu importation échoue:

import network as N
print(dir(N), N.__all__)
import network.model as M

['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'transformer'] ['model', 'view']
Traceback (most recent call last):..........
AttributeError: 'module' object has no attribute 'model'

Edit: C'était une importation circulaire.

La version de Python?
La Version 2.7
ce python en ligne de commande utilisez-vous pour votre application?
La question du "Comment débogage Python import échec?" n'a pas été répondu... (bien que le problème a été résolu)

OriginalL'auteur Neil G | 2011-05-26