Fix ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

To fix the "No module named MySQLdb" error, you need to install MySQL support for Python; do the following:

pip install MySQL-python

NOTE: Don't use sudo with pip. Fix your directory permissions if you find yourself needing to use sudo.

Other errors:

EnvironmentError: mysql_config not found

fix with:

sudo apt-get install libmysqlclient15-dev
Python.h: No such file or directory

fix with

sudo apt-get install python2.7-dev
View this page on GitHub.
Posted .

5 comments

  1. anonymous

    Hi,

    I have tried many different things and install MySQLdb. If I type from the interpreter import MySQLdb it works. But when I try to do it using DJANGO it fails giving this error

    : Error loading MySQLdb module: No module named MySQLdb

         args = ('Error loading MySQLdb module: No module named MySQLdb',)

         message = 'Error loading MySQLdb module: No module named MySQLdb'

  2. anonymous

    For OS X, enter this on the command line before proceeding with the install.

    export PATH=/usr/local/mysql/bin:$PATH

  3. anonymous

    Thank you so much for this! Exactly what I have been looking for! So many people have crazy methods but all that was needed was two lines -_-

  4. anonymous

    django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: this is MySQLdb version (1, 2, 3, 'final', 0), but _mysql is version (1, 2, 5, 'final', 1)

    instead of

    $ pip install MySQL-python

    install the matching version.

    $ pip install MySQL-python==1.2.3

    then

    django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: _mysql: init failed

    unfortunately, this one fixed itself somehow. i just opened up a new command line window in Ubuntu without going into the virtualenv and it worked.

  5. anonymous

    For Python 3 use mysqlclient:

    $ pip install mysqlclient

    Possible errors:

    - ImportError: No module named 'ConfigParser' (from ConfigParser import SafeConfigParser)

    - SyntaxError: invalid syntax (_KEYCRE = re.compile(ur"%\(([^)]+)\)s"))

    https://docs.djangoproject.com/en/dev/ref/databases/#mysql-db-api-drivers

Leave a Reply