Skip to content

Instantly share code, notes, and snippets.

@fcurella
Created July 27, 2012 15:22
Show Gist options
  • Save fcurella/3188632 to your computer and use it in GitHub Desktop.
Save fcurella/3188632 to your computer and use it in GitHub Desktop.
Django and Postgis on OS X

Django and Postgis on OS X

Install Homebrew

Install a few things with homebrew:

Notice that some packages give you information at the end, read it carefully. To recall that info use brew info like this: $ brew info postgresql

$ brew install python --universal

Note: if you plan on running graphical apps with this python installation add --framework as well.

Some geo dependencies:

Django doesn't currently work with Postgis 2.x, so we have to install 1.5.x (see ticket #16455). Also, PostGis 1.5 does not work with Postgres 9.2, so we are going to install v9.0.8

$ brew tap homebrew/versions
$ brew install postgis15
$ brew install postgresql9
$ brew untap homebrew/versions
$ brew install gdal geos

Create the template_postgis template database

$ createdb template_postgis
$ psql -f /usr/local/share/postgis/postgis.sql template_postgis
$ psql -f /usr/local/share/postgis/spatial_ref_sys.sql template_postgis

Create a new db:

$ createdb -T template_postgis mydatabase

Dump/Restore:

$ pg_dump -Fc mydatabase > /tmp/mydatabase.db
$ postgis_restore.pl /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql mydatabase /tmp/mydatabase.db
@rchrd2
Copy link

rchrd2 commented Jul 11, 2013

It's worth a note that Django 1.5 seems to support PostGIS 2.0 (see https://docs.djangoproject.com/en/1.5/ref/contrib/gis/install/postgis/). These instructions worked for me, but I realized that I may have been able to use 2.0 after the fact.

@mverzilli
Copy link

Thanks for this, it's really helpful! My 2 cents:

I've stumbled upon an error when running initdb (after having brew install postgis and postgresql):

FATAL: could not create shared memory segment: Cannot allocate memory

A solution to that is detailed at: http://willbryant.net/software/mac_os_x/postgres_initdb_fatal_shared_memory_error_on_leopard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment