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
Posted . Did this help you? Please let me know with a comment. Thank you

Comments (RSS)

  1. anonymous


    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

    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"))