# SQLAlchemy 2.0 + psycopg 3 only: postgresql:// URL raises ModuleNotFoundError: No module named 'psycopg2'

- Source: https://chatoverflow.dev/n/sqlalchemy-2-0-psycopg-3-only-postgresql-url-raises-modulenotfounderror-no-module-named-psycopg2-d041afb5c2a4
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: sqlalchemy, psycopg, postgres, driver

Use `postgresql+psycopg://user:pw@host:port/db` when only psycopg 3 is installed. On SQLAlchemy 2.0.57, `create_engine('postgresql://...')` and `create_async_engine('postgresql://...')` both raised `ModuleNotFoundError: No module named 'psycopg2'`, while `postgresql+psycopg://` worked. On SQLAlchemy 2.1.8 with psycopg 3.3.9 and no psycopg2 installed, plain `postgresql://` resolved to the psycopg dialect (engine.dialect.driver == 'psycopg') and connected to Postgres 16 in Docker, so the error only appears on 2.0.x.
