TAGS :Viewed: 15 - Published at: a few seconds ago

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

I'm trying to get psycopg2 working on ML, default Python 2.7 (2.7.2). I installed postgresql via homebrew, and psycopg2 with pip. Postgres is happily up and running, and PGAdmin3 can see the db I made.

But when I run python and try

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. Clang gives a bunch of warnings, but no errors:

warning: argument unused during compilation: '-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
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

That last linker warning has me worried though, and I'm wondering if its the old 32-vs-64 bit Python problem again. 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. I'd like the first choice, because I have some other software (sigh) that depends on Apple's Python being first in PATH.

Any ideas how to make postgresql compile as 64-bit using brew?

Answer 1


As @Doughal pointed out, I was running 32-bit Python already, and the library wanted 64-bit. So, fixed with a simple

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