I had the pleasure today of installing PostgreSQL and psycopg2 in a virtualenv on Lion. Here’s what I did, just so I remember in the future.
Note: These instructions assume a clean virtualenv. So if you’ve already attempted to install psycopg2 without PostgreSQL installed, and it failed, you should probably blow away your virtualenv altogether before attempting the steps below. I’m not sure what about the fact that a failure previously occurred makes further attempts fail, but I believe it’s related to
setup.cfg‘s already being partially written. At any rate, here are the steps I took:
- Install PostgreSQL via the provided binary. The installer will ask you to reboot. Once that’s done, run the installer again. This should actually install the postgres binaries — likely under
workonthe relevant virtualenv.
pip install psycopg2. This should fail but will create a
psycopg2directory under your virtualenv’s
builddirectory. (Note: I’m not sure this step is required, but it’s the order in which I proceeded.)
<virtualenv>/build/psycopg2/setup.cfgwith the following lines:
include_dirs=/Library/PostgreSQL/9.1/bin(around line 35)
library_dirs=/Library/PostgreSQL/9.1/lib(around line 46)
pip install psycopg2.