Install psycopg2 (PostgreSQL adapter for Python) on OSX

I was playing with Django with Postgres backend, and I had little difficulty installing “psycopg2” the Python DB adapter for Postgres on my Mac OSX.

I’ve installed Postgres using Postgres.app for OSX which is straight forward and standard Mac app.

But when I tried installing “psycopg2” using “pip” (the python package manager) I got an error:

$ pip install psycopg2
:
Error: pg_config executable not found.
:

I just searched for “pg_config” in my system:

$ find / -name pg_config  2>/dev/null
/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

Then added to my PATH env and pip worked:

$ export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/
$ pip install psycopg2

10 thoughts on “Install psycopg2 (PostgreSQL adapter for Python) on OSX”

  1. This also really helped me. It was the clearest, and most concise answer to this issue; while still being explained in a way that a novice would know what to do.

    Thanks!

  2. I did this in one virtualenv and it worked, then I tried doing it in another project and I couldn’t install it, anyone knows how to fix it??

  3. Thanks a lot, this is by far the most straight forward solution for the pg_config error when installing psycopg2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.