5

I am having trouble getting a simple GeoDjango app running on heroku. I have created the postgis extension for my database but I am not able to run syncdb without getting the following error:

from django.contrib.gis.geometry.backend import Geometry
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/gis/geometry/backend/__init__.py", line 14, in <module>
'"%s".' % geom_backend)
django.core.exceptions.ImproperlyConfigured: Could not import user-defined GEOMETRY_BACKEND "geos".

Any ideas what I am doing wrong? Also does anyone know of a tutorial for getting a simple geodjango project running on heroku? Thanks for your help

Jeff Ames
  • 1,555
  • 11
  • 27

3 Answers3

3

I ran into this same issue and Joe is correct, you are missing a buildpack. What I did differently was include both the heroku-geo-buildpack and the heroku-buildpack-python. Both can be included by using the heroku-buildpack-multi and adding a ".buildpacks" file to your home directory in which to include the other buildpacks.

https://github.com/ddollar/heroku-buildpack-multi

So set buildpack-multi as your buildpack and add a .buildpacks file in your project base directory:

$ heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
$ touch .buildpacks

# .buildpacks
https://github.com/cyberdelia/heroku-geo-buildpack.git#1.0
https://github.com/heroku/heroku-buildpack-python

When you push this, Heroku will install the software packages required to run python (python, pip, etc), along with the software packages required to run postgis (geos, proj and gdal).

I gave heroku-buildpack-geodjango a try but I believe it might be out of date (hasn't been updated in a year).

Jeff Miller
  • 588
  • 1
  • 3
  • 13
  • i am getting a `django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "d17s5j1dssat5d4pe". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?` when i try to `heroku run python manage.py migrate`. Any idea whts wrong?? – psychok7 Feb 08 '15 at 19:34
2

I just ran into the exact same error after using the multi buildpack method from ddollar https://github.com/ddollar/heroku-buildpack-multi with no problems up until this morning. As Jeff writes, you just point your buildpack at the multi and then add a .buildpacks file.

$ heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
$ cat .buildpacks

# .buildpacks
https://github.com/cyberdelia/heroku-geo-buildpack.git
https://github.com/heroku/heroku-buildpack-python

Also dont forget to add django.contrib.gis to the apps in settings.

Everything should go well and install the geos and gdal libs when you push to heroku but you will find that django doesnt find them and you get the error. This is because django wants the full path as per the docs:

https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/geolibs/

So add this to settings.py:

GEOS_LIBRARY_PATH = "{}/libgeos_c.so".format(environ.get('GEOS_LIBRARY_PATH'))
GDAL_LIBRARY_PATH = "{}/libgdal.so".format(environ.get('GDAL_LIBRARY_PATH'))
7wonders
  • 1,639
  • 1
  • 17
  • 34
1

It seems like you are missing some C libraries. Consider the GeoDjango Heroku buildpack:

https://github.com/cirlabs/heroku-buildpack-geodjango/

heroku create --stack cedar --buildpack http://github.com/cirlabs/heroku-buildpack-geodjango/
git push heroku master

The required libraries should be installed automatically using these commands.

Joe Tricarico
  • 363
  • 2
  • 5