简体   繁体   English

在Mountain Lion上安装psycopg2(brew + pip)

[英]Installing psycopg2 on Mountain Lion (brew + pip)

I'm trying to get psycopg2 working on ML, default Python 2.7 (2.7.2). 我正在尝试让psycopg2处理ML,默认的Python 2.7(2.7.2)。 I installed postgresql via homebrew, and psycopg2 with pip. 我通过自制软件安装了postgresql,用pip安装了psycopg2。 Postgres is happily up and running, and PGAdmin3 can see the db I made. Postgres很高兴并且正在运行,PGAdmin3可以看到我制作的数据库。

But when I run python and try 但是当我运行python并尝试时

import psycopg2

I get: 我明白了:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 67, 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

Now the output for sudo pip install psycopg2 isn't exactly clean. 现在sudo pip install psycopg2的输出并不完全干净。 Clang gives a bunch of warnings, but no errors: Clang给出了一堆警告,但没有错误:

warning: argument unused during compilation: '-mno-fused-madd' 警告:编译期间未使用的参数:' - mno-fused-madd'
warning: unused function 'Dprintf' warning: implicit conversion loses integer precision: 'long' to 'int' warning: comparison of unsigned expression < 0 is always false 警告:未使用的函数'Dprintf'警告:隐式转换失去整数精度:'long'到'int'警告:无符号表达式的比较<0始终为false
ld: warning: ignoring file /usr/local/Cellar/postgresql/9.1.4/lib/libpq.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /usr/local/Cellar/postgresql/9.1.4/lib/libpq.dylib ld:警告:忽略文件/usr/local/Cellar/postgresql/9.1.4/lib/libpq.dylib,文件是为不支持的文件格式构建的(0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0)这不是被链接的体系结构(i386):/ usr / local / Cellar / postgresql / 9.1.1 / lib / libpq.dylib

That last linker warning has me worried though, and I'm wondering if its the old 32-vs-64 bit Python problem again. 最后一个链接器警告让我担心,我想知道它是否再次出现旧的32-vs-64位Python问题。 I've tried the old: 我试过旧的:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

But no dice. 但没有骰子。

My next thoughts are: force brew to compile postgresql as x86_64, or install python from brew. 我的下一个想法是:强制brew将postgresql编译为x86_64,或者从brew安装python。 I'd like the first choice, because I have some other software (sigh) that depends on Apple's Python being first in PATH. 我想要第一个选择,因为我有一些其他的软件(叹气)依赖于Apple的Python在PATH中的第一个。

Any ideas how to make postgresql compile as 64-bit using brew? 任何想法如何使用brew将postgresql编译为64位?

As @Doughal pointed out, I was running 32 -bit Python already, and the library wanted 64-bit. 正如@Doughal指出的那样,我已经运行了32位Python,而库需要64位。 So, fixed with a simple 所以,用一个简单的固定

defaults write com.apple.versioner.python Prefer-32-Bit -bool no

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM