1

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.

flowerboy
  • 81
  • 7

1 Answers1

2

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')
bitflip
  • 3,436
  • 1
  • 3
  • 22
  • 1
    thank you! i didn't know that i then needed to specify the package i want to use instead in the engine-creation :) – flowerboy Sep 19 '22 at 13:46