Michael Fourre Michael Fourre - 2 months ago 21x
MySQL Question

ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb -- Django 1.4 & Google App Engine

This will be the second time in my life posting about almost exactly the same thing. The difference between this time and last time is about 9 months, lots of difficult learning, and the fact that for those past 9 months I have never had this issue and have frequently used MySQLdb flawlessly during the entire time period. I recognize that a similar question to this has been asked many times. I have read the responses and performed the suggested fixes. As of yet, I have still been unable to reach a successful conclusion, which is why I am posting my question.

Just to describe my environment: I'm running a Django app on Google App Engine locally using the Google App Engine Launcher. I'm using Mac OS X El Capitan.

When these apps are deployed on Google App Engine, they work flawlessly as intended. However, when running locally, I will consistently get the ImportError upon trying to run the app.

Let me list some of the things I have checked and/or tried to fix the problem:

-Installed mysql

-Installed mysql-python

-Added MySQLdb to "Libraries" section in app.yaml

-Checked PYTHONPATH at runtime to confirm that the proper directories are added to path.

-Add paths before importing as a dummy check

-Updated Google App Engine SDK

I've done even more, but can barely recall them now. When checking the path at runtime, I can clearly see the following path to the google_appengine SDK directory where MySQLdb resides:


Is this not what I'm supposed to see? Should I be pointing to something else? I've also pointed to other directories where I have other python packages installed (e.g. /Library/Python/2.7/site-packages/). What am I missing? I know I'm doing something dumb, and I'm fine with that. I just want to stop wasting my own time trying to troubleshoot such a stupid issue. I use MySQL every day in other projects, and never experience issues like this. I really don't know what it is at this point.

Let me know if I can add anymore useful information and I will happily oblige. I will put a few of my files down below in the hopes that they may be useful.


application: *omitted*
version: 1
runtime: python27
api_version: 1
threadsafe: true


- url: /favicon\.ico
static_files: static/images/favicon.ico
upload: static/images/favicon\.ico
- url: /static
static_dir: static
application_readable: true
- url: /.*
script: main.app

- name: django
version: "latest"
- name: MySQLdb
version: "latest"


from google.appengine.ext.webapp import util
import django.dispatch.dispatcher
import django.core.handlers.wsgi
from django.conf import settings
import django.core.signals
import django.db
import os

settings._target = None

app = django.core.handlers.wsgi.WSGIHandler()

def main():

if __name__ == '__main__':

settings.py (the database bit):

'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '*omitted*',
'NAME': '*omitted*',
'USER': '*omitted*',

Any help is greatly appreciated.

Here is an example of something I tried in settings.py:

import imp
import sys
import os


found = True
except ImportError:
found = False

print('Found: ' + str(found))

import MySQLdb

print('Import success')

Doing this, when I look for 'Found: false' I don't find it. I find 'Found: true' which should really tell me that there isn't any problem finding the MySQLdb module. However, when it reaches the
import MySQLdb
line, the program crashes with
ImportError: No module named MySQLdb
and the line
print('Import success')
is never reached

What's going on?

Edit: I am going to try to do this now on my Linux partition, though I don't think that anything I do there will help me figure out what to do back on Mac OS


After digging around for hours I have finally discovered the root issue. The only significant change that has occurred from the time that MySQLdb was working properly and the time that MySQLdb stopped working properly was upon my upgrading OS X to El Capitan.


otool -L /Library/Python/2.7/site-packages/_mysql.so

revealed that _mysql.so was searching for libmysqlclient.18.dylib in the /usr/lib directory when really it was located in /usr/local/lib directory. As a quick fix, I created a symbolic link by running the following (all on one line btw):

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.d‌​ylib /usr/local/lib/libmysqlclient.18.dylib

Since El Capitan has implemented Apple's "rootless" mode, and the current user (me) is unable to write to /usr/lib, creating the symlink in /usr/local/lib is adequate and probably better for a Mac user.

After performing these steps, MySQLdb was able to load properly; my app initialized and ran successfully for the first time in a long while.