sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:mysql.pymysq

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:mysql.pymysql

  • 执行代码部分
    • 报错
    • 解决方式

执行代码部分

def connect_db():
    # MySQL的用户:root, 密码:, 端口:,数据库:
    print("开始连接数据库")
    sql_user = input("user:")
    sql_passwd = getpass.getpass("input mysql password:")
    sql_host = input("host:")
    sql_port = int(input("port:"))
    sql_db = input("db:")
    engine = create_engine('mysql+pymysql://%s:%s@%s:%d/%s' % (sql_user, sql_passwd, sql_host, sql_port, sql_db)) 
    print("%s数据库连接成功" % sql_db)
    return engine
engine = connect_db() 

报错

Traceback (most recent call last):
  File "", line 1, in <module>
  File "", line 14, in connect_db
  File "/home/tarena/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py", line 423, in create_engine
    return strategy.create(*args, **kwargs)
  File "/home/tarena/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 61, in create
    entrypoint = u._get_entrypoint()
  File "/home/tarena/anaconda3/lib/python3.7/site-packages/sqlalchemy/engine/url.py", line 172, in _get_entrypoint
    cls = registry.load(name)
  File "/home/tarena/anaconda3/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 240, in load
    "Can't load plugin: %s:%s" % (self.group, name)
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:mysql.pymysql

解决方式

不知道是不是我之前重装MySQL数据库的时候删除了pymysql和sqlalchemy中文件,把这两个个库重新安装后就可以正常使用

你可能感兴趣的:(数据库连接)