0

我正在尝试使用 SQLAlchemy 连接到 MySQL 数据库,它突然开始向我抛出一个错误,我似乎无法连接,过去一个月在同一台机器上工作正常,我不确定发生了什么变化.

from sqlalchemy import create_engine

self.engine = create_engine(
    f'mysql+mysqlconnector://{self.USER}:{self.PASSWORD}@{self.HOST}/{self.DB_NAME}'
)

这是回溯:

Traceback (most recent call last):
  File "/Users/or/Desktop/options/options/journal/journal.py", line 330, in <module>
    Journal()
  File "/Users/or/Desktop/options/options/journal/journal.py", line 21, in __init__
    self.engine = create_engine(
  File "<string>", line 2, in create_engine
  File "/Users/or/Desktop/options/.venv/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py", line 298, in warned
    return fn(*args, **kwargs)
  File "/Users/or/Desktop/options/.venv/lib/python3.8/site-packages/sqlalchemy/engine/create.py", line 548, in create_engine
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/Users/or/Desktop/options/.venv/lib/python3.8/site-packages/sqlalchemy/dialects/mysql/mysqlconnector.py", line 129, in dbapi
    from mysql import connector
ModuleNotFoundError: No module named 'mysql'

它抱怨我已经尝试过安装的缺少模块: pip install mysql-connector-python并且pip install mysql-connector-python-rf如其他线程中所述,仍然无法正常工作。

谢谢你的帮助。

4

0 回答 0