Recently had this issue trying to import psycopg2 (2.8.2) into a python3 (3.5.3) project. Running macOS Sierra (10.12.6), using PostgreSQL 9.6 + pgAdmin3.
TLDR: be careful when installing SQL programs & the dynamic links that installers create
From what I can tell, the required libpq dynamic library (libpq.5.dylib
) that's compatible with psycopg2 (2.8.2) is libpq 5.9+ (libpq.5.9.dylib
)
When postgres (or other postgres-dependent programs) are installed, they may create dynamic links in /usr/lib
to the newly installed .dylib files, which may not necessarily be the ones you want.
For example, /usr/lib/libpq.5.dylib
may point to ./Applications/pgAdmin3.app/Contents/Frameworks/libpq.5.dylib
, which is version 5.6; the older version of the libpq dynamic library may not include some functions, like _PQsslAttribute
, in this case.
The solution that worked for me:
Move /usr/local/lib
up in $PATH
(since usr/lib
may only be writable by root), then create a dynamic link in /usr/local/lib
to point to /Library/PostgreSQL/9.6/lib/libpq.5.9.dylib
like this:
cd /usr/local/lib
ln -s /Library/PostgreSQL/9.6/lib/libpq.5.9.dylib ./libpq.5.dylib
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…