How to fix ImportError: No module named MySQLdb with Python Flask?

Sometimes, we want to fix ImportError: No module named MySQLdb with Python Flask.

In this article, we’ll look at how to fix ImportError: No module named MySQLdb with Python Flask.

How to fix ImportError: No module named MySQLdb with Python Flask?

To fix ImportError: No module named MySQLdb with Python Flask, we install the mysql-python package.

To install it, we run

pip install mysql-python

Then we use

engine = create_engine('mysql+mysqldb://user:password@localhost/foo')

to connect to the database with create_engine.

Conclusion

To fix ImportError: No module named MySQLdb with Python Flask, we install the mysql-python package.