0

I recently moved a django app from c:\Users\user\django-projects\foo\foobar to c:\Python25\Lib\site-packages\foo\foobar (which is on the python path). I started a new app in the django-projects directory, and added foo.foobar to the INSTALLED_APPS setting. When I try to run the dev server (manage.py runserver) for my new app, I get the error ImportError: No module named foobar.

Looking through the traceback, it's looking in the c:\Users\user\django-projects\foo\..\foo\foobar for the foobar app. I checked my PATH and PYTHONPATH environment variables, and neither point to c:\Users\user\django-projects\foo and It doesn't show up in sys.path when I run the python interpreter.

I'm guessing I somehow added c:\Users\user\django-projects\foo to django's path sometime along the development of foo but I don't remember how I did it.

So, with all that lead up, my question is "how do I make manage.py look in c:\Python25\Lib\site-packages instead of c:\Users\user\django-projects\foo?"

Thanks,

  • Lexo
Lexo
  • 470
  • 4
  • 20
  • You can change the path by editing `sys.path`. However, I am guessing that your `site-packages\foo` directory is simply missing an `__init__.py` – Wolph Aug 05 '10 at 01:32
  • Is `sys.path` the only place that `manage.py` looks? If so, how come it's still looking in the non-existent `django-projects\foo` directory? Also, I do have the `__init__.py` file in `site-packages\foo` – Lexo Aug 05 '10 at 01:41

2 Answers2

1

manage.py imports settings.py from the current directory and pass settings as parameter to execute_manager. You probably defined project root in settings.py.

laurent
  • 888
  • 8
  • 13
  • Thanks. I checked my `settings.py` and there's no trace of `django-projects` in it at all. I'm beginning to think I'm going crazy. I'll do some more testing and see what I can come up with. – Lexo Aug 05 '10 at 22:55
  • did you try to use the managed shell (`python manage.py shell`) to see what's in sys.path. `..../foo` should be the first one there. Just to check... as if it is not there, I don't know how to correct! but if it's there, I think your problem is not a path problem. Maybe permissions? Is `__init__.py` empty? – laurent Aug 05 '10 at 23:51
  • I fixed the problem (see below), but you did answer my original question, so I marked your question as the correct one. Thanks for your help! – Lexo Aug 07 '10 at 19:27
  • Happy to see it's solved! :) and thanks for the accept even with a very indirect help. – laurent Aug 07 '10 at 21:43
1

I fixed it, although I don't know which solution worked. First, I deleted the .pyc files from my project, then I reindexed my Windows search (I'm guessing this did it). This changed the error message to the correct directory. After which, i realized I had

from baz import settings

in my foobar/baz/models.py file, which was causing the problem all along. I changed this to

import settings

which fixed the problem. Thanks to laurent for all your help :-)

Lexo
  • 470
  • 4
  • 20