Google app engine + python (django) deployment error: Error loading MySQLdb module
Question: I am creating an app on Google App Engine. I am using Django 1.4 and Python
2.7. Everything works fine on localhost. But after deployment it is not
running, I keep getting this on admin logs:

    
    
        2012-12-15 15:02:41.870
    
        /base/python27_runtime/python27_lib/versions/1/lib/cacerts/urlfetch_cacerts.txt missing; without this urlfetch will not be able to validate SSL certificates.
    
        W 2012-12-15 15:02:41.870
    
        No ssl package found. urlfetch will not be able to validate SSL certificates.
    
        E 2012-12-15 15:02:46.086
    
        Traceback (most recent call last):
          File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 196, in Handle
            handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
          File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in _LoadHandler
            __import__(cumulative_path)
          File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/djangoappengine/main/__init__.py", line 28, in <module>
            setup_env()
          File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/djangoappengine/boot.py", line 82, in setup_env
            setup_logging()
          File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/djangoappengine/boot.py", line 130, in setup_logging
            if not settings.DEBUG:
          File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/utils/functional.py", line 276, in __getattr__
            self._setup()
          File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/conf/__init__.py", line 42, in _setup
            self._wrapped = Settings(settings_module)
          File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/conf/__init__.py", line 87, in __init__
            mod = importlib.import_module(self.SETTINGS_MODULE)
          File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/utils/importlib.py", line 35, in import_module
            __import__(name)
          File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/settings.py", line 6, in <module>
            import django.db.backends.mysql.base
          File "/base/data/home/apps/s~cloudwallforever/1.363864476397206865/django/db/backends/mysql/base.py", line 14, in <module>
            raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
        ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
    

Any ideas why it is happening?


Answer: The 'Django Support' documentation hints at the solution, but doesn't make it
explicit:

> Since the standard django.db.backends.mysql backend uses MySQLdb internally,
> app.yaml must reference MySQLdb in the list of libraries.

Adding the following to `app.yaml` seems to fix the ImportError:

    
    
    libraries:
    - name: MySQLdb
      version: "latest"
    

Note that MySQLdb is not currently included in the list of [available third
party
libraries](https://developers.google.com/appengine/docs/python/tools/libraries27).
I tried it on a whim and it seems to have fixed the issue for me, YMMV.[enter
link description
here](https://developers.google.com/appengine/docs/python/cloud-sql/django)

