且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Mac OS X Lion Psycopg2:找不到符号:_PQbackendPID

更新时间:2023-11-10 11:55:52

最近遇到了尝试将psycopg2(2.8.2)导入python3(3.5.3)项目的问题.使用PostgreSQL 9.6 + pgAdmin3运行macOS Sierra(10.12.6).

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:在安装SQL程序和安装程序创建的动态链接

TLDR: be careful when installing SQL programs & the dynamic links that installers create

据我所知,与psycopg2(2.8.2)兼容的libpq动态库(libpq.5.dylib)是libpq 5.9+(libpq.5.9.dylib)

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)

在安装postgres(或其他与postgres相关的程序)后,它们可能会在/usr/lib中创建到新安装的.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.

例如,/usr/lib/libpq.5.dylib可能指向版本为5.6的./Applications/pgAdmin3.app/Contents/Frameworks/libpq.5.dylib;在这种情况下,较早版本的libpq动态库可能不包含某些功能,例如_PQsslAttribute.

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.

最适合我的解决方案:

$PATH中向上移动/usr/local/lib(因为usr/lib只能由root写入),然后在/usr/local/lib中创建动态链接,以指向/Library/PostgreSQL/9.6/lib/libpq.5.9.dylib,如下所示:

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