I created a virtualenv with following installed:
$ pip freeze
aniso8601==9.0.1
attrs==22.2.0
click==8.1.3
configparser==5.3.0
Flask==2.2.2
flask-restplus==0.13.0
Flask-SQLAlchemy==3.0.2
greenlet==2.0.1
itsdangerous==2.1.2
Jinja2==3.1.2
jsonschema==4.17.3
MarkupSafe==2.1.1
mysql-connector-python==8.0.31
protobuf==3.20.1
PyMySQL==1.0.2
pyrsistent==0.19.2
pytz==2022.7
six==1.16.0
SQLAlchemy==1.4.45
Werkzeug==2.2.2
You can see I have PyMySQL and mysql-connector-python installed but still I am getting this error:
Traceback (most recent call last):
File "/home/ciasto/Dev/crud_app/src/start.py", line 1, in <module>
from todo_app.extensions import db
File "/home/ciasto/Dev/crud_app/src/todo_app/extensions.py", line 5, in <module>
db = SQLAlchemy(app)
File "/home/ciasto/Dev/crud_app/crud_app_env/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 219, in __init__
self.init_app(app)
File "/home/ciasto/Dev/crud_app/crud_app_env/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 320, in init_app
engines[key] = self._make_engine(key, options, app)
File "/home/ciasto/Dev/crud_app/crud_app_env/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 606, in _make_engine
return sa.engine_from_config(options, prefix="")
File "/home/ciasto/Dev/crud_app/crud_app_env/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 743, in engine_from_config
return create_engine(url, **options)
File "<string>", line 2, in create_engine
File "/home/ciasto/Dev/crud_app/crud_app_env/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
return fn(*args, **kwargs)
File "/home/ciasto/Dev/crud_app/crud_app_env/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 548, in create_engine
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/home/ciasto/Dev/crud_app/crud_app_env/lib/python3.10/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 163, in dbapi
return __import__("MySQLdb")
ModuleNotFoundError: No module named 'MySQLdb'
I have tried reinstalling pip install MySQL-python pip install ConfigParser pip install MySQLdb
I have tried the solutions from the ModuleNotFoundError: No module named 'MySQLdb'
but it didn't worked for me. I am using ubuntu jammy on x86 platform.
I was able to fix this issue by first installing
apt install libmysqlclient-dev
then pip install mysqlclient