问题
OS 10.8.4, Python 2.7, PostgreSQL 9.2
I've been spending the past 10+ hours trying to get Psycopg2 installed for Django and am now receiving warnings and a failure that Google can't seem to help me with:
After cleaning out all existing Psycopg2 & PostgreSQL files, reinstalling PostgreSQL 9.2 and Python 2.7, I was still getting the _PQbackendPID error when trying to install Psycopg2 with Pip. So I tried changing the ARCHFLAGS setting on install:
$ sudo env ARCHFLAGS="-arch i386 -arch x86_64" pip install psycopg2
And received several errors and warnings repeated over:
warning: no files found matching '*.py' under directory 'ZPsycopgDA'
warning: no files found matching '*.gif' under directory 'ZPsycopgDA'
warning: no files found matching '*.dtml' under directory 'ZPsycopgDA'
warning: no files found matching '*' under directory 'psycopg2da'
warning: no files found matching '*' under directory 'debian'
no previously-included directories found matching 'doc/src/_build'
warning: no files found matching 'ChangeLog'
and this:
clang: warning: argument unused during compilation: '-mno-fused-madd'
and this:
psycopg/pqpath.c:1177:17: warning: array index of '3' indexes past the end of an array (that contains 1 elements) [-Warray-bounds] PyTuple_SET_ITEM(dtitem, 3, tmp);
(that last message appeared for indexes 1-6)
and this:
./psycopg/config.h:71:13: warning: unused function 'Dprintf' [-Wunused-function]
and this:
psycopg/diagnostics_type.c:64:54: warning: implicit conversion loses integer precision: 'Py_intptr_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
errortext = PQresultErrorField(self->err->pgres, (Py_intptr_t) closure);
Finally, I get this:
Successfully installed psycopg2
HOWEVER, when I move into Python:
~/ $ python2.7
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named psycopg
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
Referenced from: /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
And our old friend _PQbackendPID has returned and I'm running out of resources to problem solve.
回答1:
It looks to me like the libpq
being linked to at runtime by _psycopg.so
isn't the same as the libpq
that was compiled against.
Check your DYLIB_LIBRARY_PATH
. Also use the install_name_tool
to see whether _psycopg.so
has an @relative
, unqualified or absolute path to libpq.dylib
.
来源:https://stackoverflow.com/questions/17046075/psycopg2-installing-not-being-read-by-python-os-10-8-4-python-2-7-postgresq