Python – No module named MySQLdb


When trying to import MySQLdb you may find that the module is not available. And experience an error such as,

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: 
No module named MySQLdb


The solution is to install MySQL-python i.e

pip-2.7 install MySQL-python


However, when trying to install MySQL-python you may then get the following error,

pip-2.7 install MySQL-python ... error:Setup script exited with error: command 'gcc' failed with exit status 1

To fix this issue install the following,

yum install mysql-devel
Rick Donato

Want to become a programming expert?

Here is our hand-picked selection of the best courses you can find online:
Python Zero to Hero course
Python Pro Bootcamp
Bash Scripting and Shell Programming course
Automate with Shell Scripting course
The Complete Web Development Bootcamp course
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial