You are here: Home Tech Buildout for Django with PostgreSQL on OS X

Buildout for Django with PostgreSQL on OS X

by Chris Shenton last modified Jul 16, 2011 01:20 PM
Need to install PostgreSQL from source so buildout of psycopg2 can find libraries, includes and commands.

PostgreSQL 8.4 just came out so I installed it from the .dmg installer on my OS X laptop. The pgAdmin3 GUI tool makes navigation through the database easy.

I decided to try changing my Django app to use PostgreSQL instead of my developer environment's 'sqlite', should be no problem.  Just add 'psycopg2' to the eggs=... directive that the 'djangorecipe' uses.

parts = django
eggs  =	psycopg2

recipe	= djangorecipe
version = 1.0.2
settings = settings
eggs	= ${buildout:eggs}
project	= filedrop

The buildout failed with mysterious messages about inability to find a file, some file, that I erroneously assumed was, even tho that file exists in the distro:

Running easy_install:
/usr/local/cshenton/Projects/smd/filedrop/django-filedrop-0.8/bin/python "-c" "from setuptools.command.easy_install import main; main()" "-mUNxd" "/usr/local/cshenton/Projects/smd/filedrop/django-filedrop-0.8/eggs/tmpFX7r84" "-Z" "/usr/local/cshenton/Projects/smd/filedrop/django-filedrop-0.8/download-cache/dist/psycopg2-2.0.11.tar.gz"

Processing psycopg2-2.0.11.tar.gz
Running psycopg2-2.0.11/ -q bdist_egg --dist-dir /var/folders/gs/gsjsxRPaGWWbfv9-XdzpyU+++TU/-Tmp-/easy_install-FTrfM_/psycopg2-2.0.11/egg-dist-tmp-U4W2tj
error: Setup script exited with error: No such file or directory
An error occured when trying to install psycopg2 2.0.11.

I tried earlier versions of psycopg2 and they failed, sometimes in the same way, sometimes in different ways. One of them failed in a way indicated it couldn't find the 'pg_config' command.  Ah, maybe I need to give it includes, libraries, and binaries.

Compile from source was easy: ./configure, make, sudo make install... I could use buildout's CMMI recipe for this and make it part of the project, but wanted to make it available system-wide.

Buildout still fails. 

Oh, the PostgreSQL files get installed in /usr/local/pgsql/... so add it's bin/ dir to my PATH in my ~/.bash_profile, then source it, and THEN run the buildout again. 

And it works. W00t!

And my application, after a few changes in my Django app's for the DB, works as well. Very nice.

DATABASE_ENGINE   = 'postgresql_psycopg2'
DATABASE_NAME     = 'filedrop'
DATABASE_USER     = 'postgres'
DATABASE_PASSWORD = 'The bombing starts in five minutes'
DATABASE_PORT     = '5432'

 Update: use buildout-built postgres

I'm working on another project that's using Postgres with Django and we're using buildout to build Postgres. We have to tweak the path so that psycopg2 can find the built pg_config command:
# we need to build this against our postgres so it finds pg_config, libraries                                                                                                                                               
recipe = zc.recipe.egg:custom
egg = psycopg2
include-dirs = ${postgresql:location}/include
library-dirs = ${postgresql:location}/lib
rpath        = ${postgresql:location}/lib
environment = psycopg2-environment

PATH = %(PATH)s:${postgresql:location}/bin

Share this: