我创建了一个虚拟环境,安装了以下内容:
$ 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
你可以看到我已经安装了PyMySQL和mysql-connector-python,但我仍然得到这个错误:
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'
我已尝试重新安装pip安装MySQL-python安装ConfigParser安装MySQLdb
我已经尝试了解决方案从ModuleNotFoundError:没有模块命名'MySQLdb'
但对我不起作用。我在x86平台上使用ubuntu jammy。
我可以先安装
来解决这个问题apt install libmysqlclient-dev
则pip install mysqlclient