2

I'm having an odd Django problem, running Django with mod_wsgi.

Django is finding urls.py, and then saying:

ViewDoesNotExist: Could not import app.views. Error was: No module named views

Bizarrely, if I have

import app

in the import statements in urls.py I don't get an error (until it hits app.views as above), but if I have

from app import views

in my import statements, I get an error.

My python path, as shown in the Django debug info, has both the containing folder and the app folder on it. If I run Python from the command line, I can import app.views just fine. I can run the app using python manage.py runserver just fine.

I've tried printing the python path to stderr from urls.py too, and it has the path to app in it.

What could be going on?

My first thought was that there might not be an __init__.py in the app folder, but there is.

Thanks!

UPDATE

In the runserver app, if I try

print app.__file__
>> \path\to\app\__init__.py

But in the wsgi version, I only see:

print app.__file__
>> \path\to\app\

In other words, it's just not finding __init__.pyc.

AP257
  • 89,519
  • 86
  • 202
  • 261

2 Answers2

3

Probably a circular dependency - something in views is importing another module, which itself is trying to import views.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • I've replaced the contents of `views.py` with `print 'hello'`, but still the same error. Argh! – AP257 Feb 25 '11 at 16:56
  • 1
    Also, I can run the Django app just fine using `python manage.py runserver`. The problem only exists with WSGI. – AP257 Feb 25 '11 at 17:04
  • 1
    If the circular import cannot be found then you can try WSGI script described at end of 'http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html' as workaround. – Graham Dumpleton Feb 27 '11 at 06:29
  • @Graham thanks - I'll try your script. Sounds like it's not an uncommon problem. – AP257 Mar 01 '11 at 15:26
  • I've since found http://stackoverflow.com/questions/3749033/problem-with-django-using-apache2-mod-wsgi-occassionally-is-unable-to-import which sounds like precisely the same thing. – AP257 Mar 01 '11 at 15:27
-2

Your web server is out of file handles. Reconfigure the WSGI app for daemon mode.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • thanks - any pointers for how to do this? (google is not being my friend today) - I'm trying WSGIDaemonProcess as defined here http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango but not succeeding. – AP257 Feb 25 '11 at 17:23
  • also, I get the error even immediately after I've restarted apache - would it have run out of file handles at that point? – AP257 Feb 25 '11 at 17:39
  • Running out of file handles would be a different error. Is more likely a circular import or import ordering problem as Daniel noted. – Graham Dumpleton Feb 27 '11 at 06:29