Skip to content

Incompatibility - psycopg2.errors not found in psycopg2cffi #133

@agger-magenta

Description

@agger-magenta

Documented in the session below.

Django's psycopg2 backend expect the errors member:

overnatningsafgift-init           |   File "/opt/pypy/lib/pypy3.10/site-packages/django/db/backends/postgresql/psycopg_any.py", line 77, in <module>
overnatningsafgift-init           |     from psycopg2 import errors, extensions, sql  # NOQA

This is how I reproduced:

>>> from psycopg2cffi import compat
... 
... compat.register()
... 
>>> import psycopg2
>>> from psycopg2 import errorcodes
>>> from psycopg2 import extensions
>>> from psycopg2 import sql
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    from psycopg2 import sql
ImportError: cannot import name 'sql' from 'psycopg2cffi' (/home/agger/src/gronlandsprojekter/overnatningsafgift/venv/lib/python3.13/site-packages/psycopg2cffi/__init__.py)
>>> 
(venv) agger@thorfinn:~/src/gronlandsprojekter/overnatningsafgift$ pip install psycopg2-binary
Collecting psycopg2-binary
  Downloading psycopg2_binary-2.9.11-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.metadata (4.9 kB)
Downloading psycopg2_binary-2.9.11-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (4.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.2/4.2 MB 5.6 MB/s eta 0:00:00
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.9.11
(venv) agger@thorfinn:~/src/gronlandsprojekter/overnatningsafgift$ python
Python 3.13.5 (main, Jun 25 2025, 18:55:22) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> from psycopg2 import errors
>>> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions