Overnight django stopped working, possibly because of an automatic package upgrade on the server. Its wsgi script now fails to load in production, but running the development server works fine. What might cause the following error?

mod_wsgi (pid=27634): Target WSGI script '/var/www/.../wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=27634): Exception occurred processing WSGI script '/var/www/.../wsgi.py'.
Traceback (most recent call last):
  File "/var/www/.../wsgi.py", line 13, in <module>
 from django.core.wsgi import get_wsgi_application
  File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 2, in <module>
 from django.core.handlers.wsgi import WSGIHandler
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 10, in <module>
 from django import http
  File "/usr/local/lib/python2.7/dist-packages/django/http/__init__.py", line 5, in <module>
 from django.http.response import (
  File "/usr/local/lib/python2.7/dist-packages/django/http/response.py", line 13, in <module>
 from django.core.serializers.json import DjangoJSONEncoder
  File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/__init__.py", line 23, in <module>
 from django.core.serializers.base import SerializerDoesNotExist
  File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/base.py", line 4, in <module>
 from django.db import models
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/__init__.py", line 4, in <module>
 from django.db.models import signals  # NOQA
ImportError: cannot import name signals

The wsgi.py file is as follows:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "....settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

This worked 24 hours ago and has stopped working - I've tried django 1.10 and 1.10.3 but both exhibit the same symptoms. apache 2.4.18, python 2.7.12.

The file /usr/local/lib/python2.7/dist-packages/django/db/models/signals.py exists, so in principle there shouldn't be anything stopping the import.

1 Answer 1


It turns out that there was a file that was not readable by the webserver, and an earlier line in the error log identified this file.

IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/protobuf-3.1.0.post1-py2.7.egg/EGG-INFO/namespace_packages.txt'

I solved the problem with:

chmod -R o+r /usr/local/lib/python2.7/dist-packages

Leaving this question up in case anyone runs into the same issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.