[SOLVED] sqlalchemy ModuleNotFoundError: No module named ‘MySQLdb’


This Content is from Stack Overflow. Question asked by flowerboy

I’m trying to use sqlalchemy to use pandas.dataframe.to_sql() but when I try to create an engine I get the mentioned error:

ModuleNotFoundError: No module named 'MySQLdb'

I see that many people have issues with this from a multitude of packages but I have not found a solution that works, I’m working on a mac OS 10.13.6 and python 3.9.6.
I tried installing a few packages and they had no effect, I cannot install mysqlclient, is this the only solution? It all seems a bit complicated to just use the very basic functions of sqlalchemy.


I think MySQLdb is no longer supported for Python3.x

Instead you can use PyMySQL like this: https://pypi.org/project/PyMySQL/

To configure your engine, use:

engine = create_engine('mysql+pymysql://username:password@host:port/database')

This Question was asked in StackOverflow by flowerboy and Answered by bitflip It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?