Error Loading MySQLdb Module and "pip install MySQLdb"

Solution 1:

Clearly installing pip install MySQL-python is the way to go. The problem is with the location of mysql_config. Look around here, this might help you depending on your OS: mysql_config not found when installing mysqldb python interface

Edit:

In case the install script fails with Command "python setup.py egg_info" failed with error code 1 in {...}, installing libmysqlclient-dev with

sudo apt install libmysqlclient-dev

should fix the issue. Thanks to @thirupathi-thangavel.

Solution 2:

brew install mysql

Path will be shown after installation is complete, use that in below command :

sudo PATH=/usr/local/Cellar/mysql/bin/:$PATH pip install mysql-python

Solution 3:

If the above method not working then try

mysqlclient

pip install mysqlclient

I did not found the above library using python version(3.9) and I installed the mysqlclient and it worked for fine.