15

I'm trying to run Django with a Postgresql backend on my local Mac OS X. I've installed Django using pip:

sudo pip install Django

I've installed Postgresql with one of the binary installers here.

But when I try to install psycopg2 I get an error (pasted below) that it can't find pg_config.

From this question it seems like I should install libpq-dev but I'm not sure how.

I've tried installing libpqxx with MacPorts, but that hasn't done anything.

How do I get libpg-dev installed? Or is there something else I'm missing?

henrietta:~ $ pip install psycopg2
Downloading/unpacking psycopg2
  Downloading psycopg2-2.4.5.tar.gz (719Kb): 719Kb downloaded
  Running setup.py egg_info for package psycopg2
    Error: pg_config executable not found.

    Please add the directory containing pg_config to the PATH
    or specify the full executable path with the option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.
    Complete output from command python setup.py egg_info:
    running egg_info

creating pip-egg-info/psycopg2.egg-info

writing pip-egg-info/psycopg2.egg-info/PKG-INFO

writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt

writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt

writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

warning: manifest_maker: standard file '-c' not found

Error: pg_config executable not found.



Please add the directory containing pg_config to the PATH

or specify the full executable path with the option:



    python setup.py build_ext --pg-config /path/to/pg_config build ...



or with the pg_config option in 'setup.cfg'.

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /Users/thomas/.pip/pip.log
Community
  • 1
  • 1
tchaymore
  • 3,508
  • 12
  • 44
  • 84

5 Answers5

23

For OSX 10.9.2 Mavericks, this is what worked for me. Try installing postgres with brew first:

brew install postgresql

Then install pg

gem install pg
esilver
  • 25,374
  • 21
  • 112
  • 159
14

So I ended up following the advice here:

http://blog.jonypawks.net/2008/06/20/installing-psycopg2-on-os-x/

Turns out I did have pg-config installed, but I had to dig around to find it a bit. Once I included that in the path, everything worked swimmingly. Here's the snippet from that link:

PATH=$PATH:/Library/PostgresPlus/8.3/bin/ sudo easy_install psycopg2

I used pip instead of easy_install and my PostgreSQL installation directory was slightly different, but that's the gist.

tchaymore
  • 3,508
  • 12
  • 44
  • 84
  • 2
    This worked A-OK for me. OSX Maverick with Postgres.app 9.2.2.0: PATH=$PATH:/Applications/Postgres.app/Contents/MacOS/bin pip install psycopg2 – Peter Lada Nov 01 '13 at 05:03
  • 6
    update for OSX Mav with Postgres.app 9.3.2.0 RC2 `sudo PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin pip install psycopg2` – metasequoia Dec 22 '13 at 01:41
  • Can't find `/bin` either. What is that directory supposed to have? – ruipacheco Mar 21 '14 at 13:40
  • 3
    Update for OSX Mav with Postgres 9.3 `PATH=$PATH:/Library/PostgreSQL/9.3/bin/ pip install psycopg2` – ayjay May 27 '14 at 23:33
4

Just install postgres from source. I'm doing that on Mac OS X. It's as easy as:

./configure 
make
sudo make install

Of course you may need extra steps like autostarting, or setting configure options, but I belive this is still most painless way of setting up on Mac OS X.

And if you for some reason want to avoid installing from source, you should look for a binary version of psycopg2, e.g. here: http://www.initd.org/psycopg/download/

sudo port install py27-psycopg2
kgr
  • 9,184
  • 2
  • 36
  • 42
2

In postgress.app on mavericks the file pg_config is in /Applications/Postgres.app/Contents/MacOS/bin/ so i fixed the problem in this way:

sudo PATH=$PATH:/Applications/Postgres.app/Contents/MacOS/bin/ pip install psycopg2
Tomas Pastircak
  • 2,829
  • 14
  • 28
pier
  • 21
  • 2
  • 1
    This was super helpful. Thanks a ton! To get this working on El Capitan, you need to use a slightly different path. `sudo PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.5/bin/ pip install psycopg2` – Jason Wiener Jun 28 '16 at 15:17
0

Using macports, this worked for me:

sudo port install postgresql96
sudo port select --set postgresql postgresql96

I believe this installs all the postgres client tools and libs, while macports has a separate port for installing the server, i.e. postgresql96-server.

joshperry
  • 37,916
  • 15
  • 83
  • 99