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
@domguard
Copy link

Thanks for this gist, really !
Worth to note that now (sept 2012) homebrew ships postgresql 9.2 under "postgresql", and this version is NOT compatible with PostGIS 1.5 (see http://trac.osgeo.org/postgis/ticket/1995 )
So to make this work, I had to brew install postgresql9 (which links to 9.0.8) and edit the postgis15 formula to link it to this package.

@fcurella
Copy link
Author

fcurella commented Oct 9, 2012

Thanks @domguard, I've updated the gist.

@bfla
Copy link

bfla commented Jan 8, 2013

Thanks @fcurella. This saved me a lot of time. I had a few additional problems getting Geodjango/PostGIS running on Mac OS X, which I wrote up in case other people run into them: http://stackoverflow.com/questions/3567352/geodjango-syncdb-errors-from-geodjango-tutorial/14221129#14221129

@striveforbest
Copy link

thanks! helped a lot

@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