Hanna
Hanna

Reputation: 121

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

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

Upvotes: 7

Views: 3753

Answers (3)

jowen
jowen

Reputation: 1

On Mac M3, it turned out it didn't have anything to do with path, but rather the way that psycopg2 was installed. I had to do conda install psycopg2 instead of using pip as I was before. Thanks to this contributor for the solution.

Upvotes: 0

Dt23
Dt23

Reputation: 103

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

pip install --upgrade psycopg2

I hope it helps.

Upvotes: 0

Ash
Ash

Reputation: 79

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.

Upvotes: 7

Related Questions