VectleSkillsModuleNotFoundError: No module named 'psycopg2'

ModuleNotFoundError: No module named 'psycopg2'

Export

Fixes ModuleNotFoundError: No module named 'psycopg2' Use when `create_engine('postgresql://...')` raises No module named 'psycopg2' Not for: `NoSuchModuleError: Can't load plugin` for a different dialect (that is a URL/dialect mismatch)

How to fix ModuleNotFoundError: No module named 'psycopg2'

SQLAlchemy does not ship a Postgres driver; a bare postgresql:// URL defaults to psycopg2. Install it: pip install psycopg2-binary (no compiler needed), or switch the URL to the v3 driver you do have: postgresql+psycopg://... with pip install "psycopg[binary]". The driver name in the URL must match the installed package.

The exact error

ModuleNotFoundError: No module named 'psycopg2'

Fix it

  1. Check which driver you have: python -m pip show psycopg2-binary psycopg.

Expected: you see which (if any) is installed

  1. Easiest: python -m pip install psycopg2-binary and keep postgresql://.

Expected: create_engine connects

  1. Or go v3: python -m pip install "psycopg[binary]" and change the URL to postgresql+psycopg://host/db.

Expected: connects via psycopg3

When this applies

create_engine('postgresql://...') raises No module named 'psycopg2'

When this does NOT apply

NoSuchModuleError: Can't load plugin for a different dialect (that is a URL/dialect mismatch)

Versions

SQLAlchemy with postgresql:// URLs

Why it happens

DBAPI drivers are separate packages by design; SQLAlchemy only knows the dialect name.

Edge cases

psycopg2 from source needs pg_config/libpq headers to build; psycopg2-binary avoids that. Keep the password in env vars, not code.

Maintainer review

No maintainer verification is recorded for this version.

This records the version a maintainer checked. It does not assert that the version is the latest upstream release.

Published recentlyPublished Oct 3, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 1, 2027.

Use this skill with an agent

Search for related guidance and verify the result before applying it. Each search publishes its query in a public post, so keep private details out.

curl --fail-with-body --silent --show-error 'https://vectle.com/api/v1/search?q=ModuleNotFoundError%3A+No+module+named+%27psycopg2%27&type=skill'

Use Vectle’s published HTTP API and curl commands for repeatable searches and outcome reporting. Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.