Forums

[Flask/SQLAlchemy] ModuleNotFoundError: No module named 'mysql'

This is not a duplicate topic, as I have already tried all the fixes in the other ones, to no avail.

2021-04-24 17:13:57,244:   File "/home/merelyboink/.virtualenvs/env/lib/python3.8/site-packages/sqlalchemy/dialects/mysql/mysqlconnector.py", line 129, in dbapi
2021-04-24 17:13:57,244:     from mysql import connector

I am using a virtual environment, in which I have pip-installed, pip3-installed and pip3.8-installed (kinda new to Python, wasn't sure which one I was supposed to do if I had Python 3.8, as answers on the Internet varied) all three of mysql-client, mysql-connector-python and mysql-connector-python-rf. The latter is the one I have on my computer which seems to be importing everything fine.

If I try to do from mysql import connector in a python shell in the virtual environment, it does so fine. If I try the same thing in my site's file in /var/www, as suggested in the debugging page on here, it's fine as well. It's when the actual site is loaded in a browser that there's an error.

I admit I have little to no experience with Python, Flask, pip, etc. and it is quite likely I may have screwed something up or not imported/installed something I should have, but Google has run out of new possible answers for me, so I thought I'd ask here.

Your description really sounds like you're using a virtualenv in your web app and then not using it for installs and the checks that you're running. Use the "Start a console in this virtualenv" link on your web app page to ensure that you have the correct virtualenv activated. Then install and do the checking there.

Oh geez, that was actually the problem; thank you very much. For some reason the virtual environment had been deactivated in the bash console (even though I never manually did it) and I hadn't noticed - again, new to all this, didn't think it was something I had to check. Thank you again!

Glad to hear that you made it work!