Installing psycopg2 on OS X

I have recently been doing some python development that uses the psycopg2 driver for PostgreSQL. On Linux, this worked wonderfully, and everything was installed using the regular easy_install method with no troubles. However on OS X it wasn’t quite so easy.

First I tried using easy_install but it failed with a long list of gcc warnings and errors. Looking near the beginning of the errors I saw:
Warning: /bin/sh: pg_config: command not found followed by
./psycopg/connection.h:27:22: error: libpq-fe.h: No such file or directory Well this makes sense as I’m using PostgreSQL Plus for OS X, and it doesn’t put it’s header files or libraries in a standard place. There is an easy workaround though.

Thanks to Luke Tucker who provided this easy solution: PATH=$PATH:/Library/PostgresPlus/8.3/bin/ sudo easy_install psycopg2

Original Method

This is left here for historical purposes. I recommend using the above command instead.
We’ll need to download the psycopg2 package and install it manually. Don’t worry, this is very easy and doesn’t require much work at all.

  1. Open you favorite terminal application.
  2. Download the package. Extract the package, enter the directory.
    curl -o psycopg2.tar.gz
    tar xzf psycopg2.tar.gz
    cd psycopg2-${version}
  3. Edit the setup configuration file. Use whatever editor you’re comfortable with.
    vim setup.cfg
  4. Uncomment the include_dirs line and change it to read:
  5. Uncomment the library_dirs line and change it to read:
  6. Save and quit your editor.
  7. Finally, build and install the package.
    sudo python install

And now you should have a working PostgreSQL driver for Python. This was very useful for me since I like to use SQLAlchemy for my database work in Python and it uses psycopg2.


As a alternative method, you can replace steps 4 and 5 above with:

  • Uncomment pg_config line and change it to read:

Thanks, pacopablo!

NoteHack, Ruby on Rails and TextMate

So, I don’t update this blog very often. Mainly because I find that I just don’t really have time to sit down and write a nice long update all the time. And, I don’t really enjoy writing long posts. They always turn into rants and I find that most of the longer posts I write are pretty useless to everyone but me. However, I do like my short little “OMG THIS IS NEAT” posts so you may see this blog shift more to that end of the spectrum. Anyways, on with the real shit you want to read. :D

I play NetHack quite a bit as many of you are aware. Well, I find my memory isn’t quite up to the challenge sometimes, especially when my games span over an entire week. I’ve decided to write a website that would be a note-taking system designed to aid NetHack players. I call it NoteHack and you can find it at It’s a pretty fun project, and it will be continually improving. I’ve been really excited about working on it every night and don’t see myself dropping this project like the others. I’ve been using Ruby on Rails for this project, which brings me to the next topic.

Ruby on Rails is a rapid development framework that has been gaining attention very quickly the last couple years. I’ve used TurboGears, which is a similar framework for python, but found it a bit harder to jump into. However, this could just be because it was the first framework of the type I used, and so my TurboGears experience has probably helped me learn RoR. Also, RoR is quite a bit more mature than TurboGears, and has much more complete documentation, which is a huge plus. Anyways, if you have an idea for a neat little (or big) webapp, I recommend checking out Ruby on Rails, you won’t regret it.

And for my last little plug, we have TextMate, a graphical text editor geared towards web programming. I’ve been using it the entire time I’ve worked on NoteHack and it’s a pretty robust little application. I like that it has a single purpose and it does that well. It’s not trying to be a godly text editor that can syntax highlight the configuration file for the proprietary software your grandmother uses to make to-do lists. But, I’m a minimalist when it comes to software, so this may be an opinion only shared by me.

Sorry if you aren’t a coder, this post probably wasn’t very interesting to you. :(