Error loading Mysqldb module in Python Django
Question: I am currently working on Ubuntu 14.10/Python/Django/MySQL and encountering
the following error when I try to run:

    
    
    $python manage.py makemigrations polls
    

or

    
    
    $python manage.py migrate polls
    

I have also tried syncdb The error is:

> (Aaronpythonenv)aaron@aaron-N550JK:~/mysite$ python manage.py makemigrations
> polls Traceback (most recent call last): File "manage.py", line 10, in
> execute_from_command_line(sys.argv) File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/core/management/**init**.py", line 338,
> in execute_from_command_line utility.execute() File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/core/management/**init**.py", line 312,
> in execute django.setup() File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/**init**.py", line 18, in setup
> apps.populate(settings.INSTALLED_APPS) File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/apps/registry.py", line 108, in
> populate app_config.import_models(all_models) File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/apps/config.py", line 198, in
> import_models self.models_module = import_module(models_module_name) File
> "/usr/lib/python2.7/importlib/**init**.py", line 37, in import_module
> **import**(name) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/contrib/auth/models.py", line 41, in
> class Permission(models.Model): File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 139, in
> **new** new_class.add_to_class('_meta', Options(meta, **kwargs)) File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 324, in
> add_to_class value.contribute_to_class(cls, name) File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/db/models/options.py", line 250, in
> contribute_to_class self.db_table = truncate_name(self.db_table,
> connection.ops.max_name_length()) File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/db/**init**.py", line 36, in
> **getattr** return getattr(connections[DEFAULT_DB_ALIAS], item) File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/db/utils.py", line 240, in **getitem**
> backend = load_backend(db['ENGINE']) File
> "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/db/utils.py", line 111, in load_backend
> return import_module('%s.base' % backend_name) File
> "/usr/lib/python2.7/importlib/**init**.py", line 37, in import_module
> **import**(name) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-
> packages/Django-1.8-py2.7.egg/django/db/backends/mysql/base.py", line 27, in
> raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module:
> No module named MySQLdb

I have used PIP to install mysql-python to my environment which I recieved
another error. I then used sudo apt-get command to install correct the error
PIP brought up.

massive thank you in advance please let me know if I need to add anything
else.


Answer: I faced somewhat similar problem. Try these steps:

1). Upgrade `pip` to the latest version.

    
    
    sudo pip install pip --upgrade
    

2). Build the dependencies for python-mysqldb libraries:

    
    
    sudo apt-get build-dep python-mysqldb
    

3). Install the Python MySQL libraries:

    
    
    sudo pip install MySQL-python
    

