Re: ImportError: symbol not found in flat namespace '_PQbackendPID'

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Gil Sousa <gilsousa(at)gmail(dot)com>
Cc: psycopg(at)lists(dot)postgresql(dot)org
Subject: Re: ImportError: symbol not found in flat namespace '_PQbackendPID'
Date: 2022-09-07 00:08:18
Message-ID: CA+mi_8Yqqfde-dPSWv0QxJXEzK91MT0eXq7t93M4RjjRpaf=xQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Hello,

On Tue, 6 Sept 2022 at 17:06, Gil Sousa <gilsousa(at)gmail(dot)com> wrote:
>
> Hi all,
>
> I am trying to use psycopg2 for the very first time, though I am stumbling with an error when trying to import the module:
>
> ✗ python3.9 radars_import.py
> Traceback (most recent call last):
> File "/Users/gilsousa/Documents/git Projects/ReportGen/radars_import.py", line 2, in <module>
> import psycopg2
> File "/Users/gilsousa/Library/Python/3.9/lib/python/site-packages/psycopg2/__init__.py", line 51, in <module>
> from psycopg2._psycopg import ( # noqa
> ImportError: dlopen(/Users/gilsousa/Library/Python/3.9/lib/python/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_PQbackendPID'
>
> I made sure that I have the packages installed, both psycopg2 and psycopg2-binary. I even tried to uninstall both and just try one at a time, also didn't work.

You should install only one of them. If you are using an apple M1,
psycopg2-binary doesn't actually install a binary package and falls
back to building from source.

> How can I fix this problem?

I don't have a macOS but the problem has surfaced often, according to
google. It seems related to the wrong installation of the libpq, and
it doesn't help that a few days ago Homebrew has broken the libpq
installation <https://github.com/psycopg/psycopg2/issues/1492>.

See https://gist.github.com/peter-gy/0ebe072acb9065944ecb04d95a4c3096
for an example of someone fixing your problem.

Cheers

-- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message Stefan Knecht 2022-10-17 11:25:14 Puzzling situation with threads and psycopg2 on RDS
Previous Message Gil Sousa 2022-09-06 16:06:28 ImportError: symbol not found in flat namespace '_PQbackendPID'