'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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source