5

ImportError: no module named location.models at the following line:

from location.models import Zipcode 

But there is a models.py, an __init__.py, and a Zipcode model in an installed app called location in my project.

Further, the module is easily imported in the python shell using the same command. What could be the problem here? Thanks for your ideas!

3
  • I'd check that you have your pythonpath set up correctly. Commented Jul 18, 2013 at 17:32
  • Would it be accessible in the python shell if it was not on the pythonpath? Commented Jul 18, 2013 at 17:33
  • You likely have two different pythonpaths in the two environments. You don't tell us anything about your setup, or indeed whether you're running the shell in a similarly configured environment. Commented Jul 18, 2013 at 17:37

1 Answer 1

4

Thanks for your commentary @Marcin. Turns out that I had a file called location.py in my views.py folder, which was causing some kind of conflict. I renamed this file location_view.py and voila.

So moral of the story, I guess, is check to make sure that you dont have any name conflicts in an app when you are trying to import an app of the same name..

Sign up to request clarification or add additional context in comments.

3 Comments

Ok well if you can explain better please be my guest. I will accept your answer. Thanks
This is why you should use relative paths when importing modules.
If anyone wants to post a more succinct answer feel free. I'm still noob status being more front-end oriented...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.