Installing psycopg2 on Mac OS X 10.6 with a 64bit Python
While installing a Django application that uses Postgres on my MacBook with Mac OS X 10.6 (Snow Leopard), I ran into some problems that were all over the net. The symptom was that when I tried to pip install the app's requirements, I got a traceback with something like this for psycopg2:
ImportError: dlopen([...]/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID ... Expected in: flat namespace
Searching the web for this found lots of things, but they didn't seem to work for me... because of some dead bodies in my Mac's basement. Basically this errors happens due to a mismatch of 32 or 64 bitness of Python, psycopg2, and Postgres. I had installed Postgres from the official installer (9.1.1), Python 2.7 was standard from the system (which is 64bit). First attempt to fix the mess, following a tipp from Anna Vester, I tried to recompile psycopg2:
pip uninstall psycopg2 ... env ARCHFLAGS="-arch x86_64" pip install psycopg2
I'm not using sudo, because I'm in a virtualenv and also I didn't dual install for i386 as suggested in the blog post. There were a lot of posts out there telling me simply to reinstall psycopg2, which didn't get me anywhere.
But... even with this it didn't work for me. I found some other hints out there that got me looking in the right direction. The second problem was that I had an old version of Postgres around, from when my MacBook was running 10.4. The pg_config from that old version didn't like the psycopg2, even in 64bit. Pointing my path to the new postgres bin directory instead of the old one solved that too.