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.