如何修复 sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
问题
运行使用 SQLAlchemy 或 SQLModel 的 Python 应用时,你可能会遇到以下错误:
sqlalchemy_error_trace.txt
...
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/deprecations.py", line 281, in warned
return fn(*args, **kwargs) # type: ignore[no-any-return]
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/create.py", line 550, in create_engine
entrypoint = u._get_entrypoint()
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/url.py", line 758, in _get_entrypoint
cls = registry.load(name)
File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/langhelpers.py", line 375, in load
raise exc.NoSuchModuleError(
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres解决方案
当你使用错误的数据库 URL时会出现此错误:
你的数据库 URL 如下所示:
postgres_url_fix.txt
postgres://user:password@localhost/database但方案部分需要是 postgresql,而不是 postgres。
postgresql_url_fixed.txt
postgresql://user:password@localhost/databaseIf this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow