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

2

7

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

Teutonize answered 1/4, 2022 at 23:37 Comment(2)
This: from psycopg2._psycopg import does not make sense. Is this something you are doing or is coming from some code you are working with? What happens if you do: import psycopg2? Add answers as update to question.Jule
Also experiencing this - that error will also occur with with a simple import psycopg2Atrice
B
8

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.

Beriberi answered 19/7, 2022 at 23:25 Comment(1)
I have no idea how or why this worked for me. It did though...Rhinal
B
0

I had a similar problem. To resolve it I updated psycopg2 to the latest version:

pip install --upgrade psycopg2

I hope it helps.

Balanchine answered 20/6, 2023 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.