[Answer]-Django – ImportError: No module named city

1πŸ‘

I assume you are using django 1.4 or later because of what is in your project folder.

Did you create the top-level directory with django-admin.py startproject? I don’t see the __init__.py file at the top level, although the project directory with settings.py and urls.py is there. Create an empty file called __init__.py at the top level (sibling of manage.py) and see if that helps.

0πŸ‘

Put your city (files which you want to import) in root dir of main application.
If IDE(PyCharm for an example) wont worry about import this module – than the problem was in paths.

I’ve smashed with this problem at once. And the problem paths were.

πŸ‘€dikkini

0πŸ‘

So I managed to fix the errors. Maybe I forgot some important info on the question but here is the explanation:

I downloaded PyDev for Eclipse and rebuilt the project from scratch. So, when I was writing the imports, Eclipse complained it was not right. Well, I went back to Django tutorial and there is import city, so I was right. I accepted the suggestion from Eclipse and it changed to from city.models import City and it went ok. So I tested with the old project and changed every import, and it validated and synced with no errors.

Now I’m very confused, how could Django documentation be wrong? Or is this Python-version or distro peculiarity? Well, nevermind, it is now working. Thanks everybody πŸ˜›

πŸ‘€ranieri

Leave a comment