I’m trying to refactor some python code and I’m stuck with an import error I don’t understand. I suspect there might be a circular dependency somewhere but I don’t see it, and I’m not getting much in the way of hints from the error messages. The codebase is large, but there are two modules of interest here:
radian/models.py defines a class called ACount
datalayer/radian.py has the following line in it:
from radian.models import ACount
When I run the code (either interactively or from the main program) the imports fail in a way that doesn’t make sense to me.
>>> from radian.models import ACount
>>> import datalayer.radian
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/leopd/dev/dbproj/datalayer/radian.py", line 10, in <module>
from radian.models import ACount
ImportError: No module named models
My best guess is that there’s a circular dependency somewhere — that radian is importing something that imports datalayer. But I don’t see it. And the error message doesn’t make any sense to me. Any ideas what’s going on?
— UPDATE —
I’m using python 2.6.1 on Mac. The __init__.py files have some code in them, but they only import from standard python packages.
Any module in the
datalayerfolder (includingradian.py), when it seesfrom radian, will assume thatdatalayer/radian.pyis the relevant module. You might need to doin
datalayer/radian.pyand other similarly affected modules, and then check all your imports to ensure that they’re absolute. You may be able to get away with renamingdatalayer/radian.pyand the imports which reference it, depending on where that module is referenced from.