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.

3
  • Possible duplicate of Problems using MySQL with AWS Lambda in Python Commented May 5, 2019 at 23:33
  • Not a duplicate, but related - thanks for the links. Tried updating the SQLALCHEMY_DATABASE_URI with mysql+pymysql without success also... Commented May 6, 2019 at 1:07
  • Have you tried the mysql_config fix for Mac here? stackoverflow.com/a/12708157/8751739 Commented May 26, 2019 at 1:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.