Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

python - Mac OS X Lion Psycopg2: Symbol not found: _PQbackendPID

I recently upgraded to Mac OS X Lion and am trying to get psycopg2 working again with python 2.6. The instructions on previous sites to force Python to run in 32 bit more (seen places like here: http://favosdream.blogspot.com/2009/09/make-psycopg2-and-readline-work-in-snow.html ) aren't giving any luck. Even trying to force python to 32 bit using arch -i386 python is still giving me the error:

symbol not found: _PQbackendPID
  Referenced from: /Library/Python/2.6/site-packages/psycopg2/_psycopg.so
  Expected in: flat namespace
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...