操作系统 10.8.4、Python 2.7、PostgreSQL 9.2
在过去的 10 多个小时里,我一直在尝试为 Django 安装 Psycopg2,现在收到警告和 Google 似乎无法帮助我解决的故障:
在清除所有现有的 Psycopg2 和 PostgreSQL 文件,重新安装 PostgreSQL 9.2 和 Python 2.7 后,我在尝试使用 Pip 安装 Psycopg2 时仍然收到 _PQbackendPID 错误。所以我尝试在安装时更改 ARCHFLAGS 设置:
$ sudo env ARCHFLAGS="-arch i386 -arch x86_64" pip install psycopg2
并收到多次重复的错误和警告:
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'
和这个:
clang: warning: argument unused during compilation: '-mno-fused-madd'
和这个:
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);
(最后一条消息出现在索引 1-6 中)
和这个:
./psycopg/config.h:71:13: warning: unused function 'Dprintf' [-Wunused-function]
和这个:
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);
最后,我明白了:
Successfully installed psycopg2
但是,当我进入 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
我们的老朋友 _PQbackendPID 又回来了,我解决问题的资源已经用完了。