Import error with psycopg2: symbol not found in flat namespace '_PQbackendPID'

Viewed 977

Does anyone know how to fix this import error? I am working on macOS Monterey version 12.0.1.

from psycopg2._psycopg import (# noqa
ImportError: dlopen(/Users/myname/data-env/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_PQbackendPID'

Update: The error is pointing at "import psycopg2" in my code, and then to "from psycopg2._psycopg import" in /Users/myname/data-env/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so

1 Answers

I encountered the same. It turned out that the version of pg_config on my path was an x86 binary, but I was using ARM Python. If you use Postgres.app, then recent versions are universal (x86 and ARM), and you can do PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH" pip install --force-reinstall psycopg2-binary==whatever.version.

Related