0

I have a Flask app up and running on my localhost. I normally instantiate the SQLAlchemy object to db with db = SQLAlchemy() and then use a few basic functionalities, like: db.drop_all(), db.create_all(), db.session.add(MyClass), db.session.commit().

Used Zappa to deploy my Flask web app to AWS Lambda, and even though I froze my pip requirements, I'm getting the following error:

ImportError: cannot import name '_mysql' from 'MySQLdb'

Now, I ran into this question, but it considers pure SQLAlchemy ORM, and new package (outside my venv, from what I understood).

I was wondering what would be the best way to solve my issue with my current setup (I normally don't create the engine, for example).

Any ideas/suggestions?

Thanks a lot.

EDIT

After a lot of investigating, it seems that there's a bug in the _mysql module. Reading it's GitHub docs:

Versions of MySQL Connector/C may have incorrect default configuration options that cause compilation errors when mysqlclient-python is installed. (As of November 2017, this is known to be true for homebrew's mysql-connector-c and official package)

Modification of mysql_config resolves these issues as follows.

Change

# on macOS, on or about line 112:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "

to

# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"

But I just can't seem to find mysql_config. While typing nano mysql_config on the terminal (with my venv activated), I get an empty file. I would imagine that solving this configuration would solve the module.

lowercase00
  • 1,917
  • 3
  • 16
  • 36
  • Possible duplicate of [Problems using MySQL with AWS Lambda in Python](https://stackoverflow.com/questions/35763380/problems-using-mysql-with-aws-lambda-in-python) – Matt Healy May 05 '19 at 23:33
  • Not a duplicate, but related - thanks for the links. Tried updating the SQLALCHEMY_DATABASE_URI with `mysql+pymysql` without success also... – lowercase00 May 06 '19 at 01:07
  • Have you tried the mysql_config fix for Mac here? https://stackoverflow.com/a/12708157/8751739 – naaman May 26 '19 at 01:29

0 Answers0