First time here? Check out the FAQ!
1

ImportError: cannot import name content

I try to develop a site with askbot as one of its applications. Instead of installing askbot with e.g. easy_install, I grabbed the latest sources from git, and started to build around that. I worked my way across all the required dependencies, installing them one by one. The Django project using askbot is now able to find askbot modules and related dependencies without a problem.

Now, when I try to run syncdb and continue from there, I get the following error:

> manage syncdb
Traceback (most recent call last):
  ...
  File "c:\git\askbot-devel\askbot\models\__init__.py", line 22, in <module>
    from askbot.models.question import Question, QuestionRevision
  File "c:\git\askbot-devel\askbot\models\question.py", line 22, in <module>
    from askbot.models import content
ImportError: cannot import name content

While inspecting the askbot sources, I think I found a circular dependency between models/__init__.py (from askbot.models.question import Question, QuestionRevision) and models/question.py (from askbot.models import content). I guess the second import comes basically back to module __init__ to see what is exported, and __init__ is still not initialized. It might be that this behavior is due to my python version (2.7), but anyway it would be nice to get expert's opinion what is happening here.

From generic refactoring point of view, I think it's good to avoid circular dependencies. Perhaps you have already some plans to fix this problem? This assuming that my assumption here is the correct one :)

jane5ky's avatar
13
jane5ky
asked 2011-07-28 09:06:46 -0500
edit flag offensive 0 remove flag close merge delete

Comments

testing on 2.7 now, will let you know soon how it goes.
Evgeny's avatar Evgeny (2011-07-28 09:21:55 -0500) edit
What database and the version of django are you using?
Evgeny's avatar Evgeny (2011-07-28 10:15:43 -0500) edit
add a comment see more comments

1 Answer

0

Hi there, I could not reproduce your error, but I would like to test on your versions of django and the same database, and same version of the python db adapter.

Most likely it is a missing dependency problem and not circular import. If you like to debug the import problem - add print statements before and after the suspect import. Once you find a place like that - go one level deeper and continue.

I will add a requirements file soon, to ease the installation of askbot with pip in the cases like yours. Someone already pointed out that it is not easy to debug dependency issues in askbot, we'll need to add more explicit checks for that.

Evgeny's avatar
13.2k
Evgeny
updated 2011-07-28 10:58:09 -0500, answered 2011-07-28 10:38:13 -0500
edit flag offensive 0 remove flag delete link

Comments

Hi and thanks for a fast response. Python version = 2.7.1, environment = windows 7. As database I try to use sqlite, which I'm sure will bring additional problems. However I'm not sure why selection of database would introduce such error; IIUC, syncdb is in a phase trying to go through the modules to create SQL for the database to use. I pinpointed the problem with printing method as you suggested, result can be seen here: http://pastebin.com/1Nf2sTBX. I inserted prints before and after relevant modules and relevant imports ...
jane5ky's avatar jane5ky (2011-07-28 11:33:20 -0500) edit
... Looks like slugify import triggers second round of imports towards model. In case of missing dependencies, I would expect to get ImportError: No module named <missing import>, looks like this isn't such case however.
jane5ky's avatar jane5ky (2011-07-28 11:34:43 -0500) edit
all of the necessary dependencies are listed in setup.py - do you have all of those installed? To install everything manually - run "pip install modulename==version_number" or just "pip install modulename". In addition - please make sure that your settings.py has all the necessary pieces for askbot - they are listed in askbot/setup_templates/settings.py. First thing - I would check that you have all the deps and everything in the settings.py. I am pretty sure there are no fatal circular import issues.
Evgeny's avatar Evgeny (2011-07-28 11:46:46 -0500) edit
True, the messages are not always helpful - I will make sure to add more of the explicit startup self-checks.
Evgeny's avatar Evgeny (2011-07-28 11:48:40 -0500) edit
Thanks Evgeny, you were right. The missing dependency was "unidecode". Looks like python indeed is good at swallowing dependencies - or perhaps there is try-except somewhere hiding the real issue. Anyway, you rock! - keep up the good work :)
jane5ky's avatar jane5ky (2011-07-28 12:05:30 -0500) edit
add a comment see more comments