Thursday, February 28, 2019

Re: Django 1.11: AttributeError: 'module' object has no attribute 'setup_environ'

Managed to fix it by loading Django as a separate library...
These are the things I had to do...
Used following link to create a libs directory and install django in it (via pip - instructions on the page) - also followed the instructions on this page for creating a

Removed django from my app.yaml
- name: django
  version: "1.11"

commented out these lines from my
#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
#from django.conf import settings

seems I had this in my app.yaml already
  DJANGO_SETTINGS_MODULE: 'core.settings'

That's about it...oh - also removed the changes I made to...


Haven't deployed it yet - but at least the dev_appserver is now running properly.

On Friday, 1 March 2019 06:41:55 UTC+11, Chi Shiek wrote:
This is related to a bug I raised against app engine while tying to migrate from django 1.5 to 1.11.

The issue is I have an app running on app engine using django 1.5.
Recently I was making a number of major updates to the app and decided to convert to django 1.11 as part of that update.

Everything seemed to work fine on my local dev_appserver, but when I deployed it to app engine, it threw an error similar to this...

ERROR    2019-02-28 19:01:49,710]
Traceback (most recent call last):
  File "/home/cshiek/Programs/google-cloud-sdk-1.9.83/platform/google_appengine/google/appengine/runtime/", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/cshiek/Programs/google-cloud-sdk-1.9.83/platform/google_appengine/google/appengine/runtime/", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/home/cshiek/Programs/google-cloud-sdk-1.9.83/platform/google_appengine/google/appengine/runtime/", line 96, in LoadObject
INFO     2019-02-28 19:01:49,720] default: "GET /Common?action=%5B%22logout%22%5D HTTP/1.1" 500 -
  File "/home/cshiek/Programs/google-cloud-sdk-1.9.83/platform/google_appengine/google/appengine/ext/django/", line 82, in <module>
    management.setup_environ(settings, original_settings_path=settings_path)
AttributeError: 'module' object has no attribute 'setup_environ'

I downloaded the app back to my local development server and built a clean python environment using only the exact modules I needed - and then I saw the same setup_environ error.
The module indicated has the following code which is throwing the error.

  settings = __import__(settings_path)
  management.setup_environ(settings, original_settings_path=settings_path)
except ImportError:

I changed the code to 
  settings = __import__(settings_path)
  management.setup_environ(settings, original_settings_path=settings_path)
except AttributeError:
except ImportError:

And everything works fine.
My problem is that the changed module appears to be inside the google-cloud-sdk and therefore I cannot change it in production.

My app.yaml point to django 1.11

I've searched the net and no one seems to have encountered this problem before...there is a lot about setup_environ, but nothing that addresses this particular issue.

I even raised a ticket against app engine ( but received a reply that it was a django problem.

Question is - has anyone else come across this problem in the app engine environment - and how did you resolve it?


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment