Mac OS X Lion Psycopg2: Symbol not found: _PQbackendPID

人走茶凉 提交于 2019-12-11 22:31:16

问题


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

回答1:


I had this problem too on Snow Leopard/10.6.8, and just lost a half a day in the middle of a pretty intense contract. Not fun. I ended up fixing it by a) fully removing all postgres versions and rebooting, b) fully removing all my psycopg2 installs (use locate and be ruthless), c) upgrading my system python to 2.7, d) reinstalling virtualenv and pip so they pointed at the right python version, and then e) following the instructions on this page, starting with install postgres 9.1 from the dmg installer:

http://hardlifeofapo.com/psycopg2-and-postgresql-9-1-on-snow-leopard/

Ultimately it was this easy:

virtualenv your_virtual_env_name
. your_virtual_env_name/bin/activate
export ARCHFLAGS="-arch i386 -arch x86_64"
export PATH=$PATH:/Library/PostgreSQL/9.1/bin
pip install psycopg2

Good luck!




回答2:


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



回答3:


Did you try arch -i386 python2.6 if you are using the Apple-supplied Python 2.6 in /usr/bin/python2.6? But if you are still running a 32-bit version of psycopg2 and the PostgreSQL client libraries, it might be a good time to install newer 64-bit or 64-bit/32-bit universal versions. MacPorts can help with that.



来源:https://stackoverflow.com/questions/6999105/mac-os-x-lion-psycopg2-symbol-not-found-pqbackendpid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!