Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgis isn't an available database backend

I'm facing this error when setting up geodjango in a working django 1.9 app.

My app is living inside a amazon EC2 instance plus a RDS postgres instance.

The error is:

django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'postgresql', 'sqlite3

What I've done:

  • Install GEOS, PROJ.4 and PostGIS as described in geodjango doc.
  • Install PostGIS in amazon RDS as described in amazon doc.
  • Modify my project settings.py to include:

    • INSTALLED_APPS = (... 'django.contrib.admin', ... 'django.contrib.gis')
    • GEOS_LIBRARY_PATH = '/usr/local/lib/libgeos_c.so'
    • DATABASES = { ... 'ENGINE': 'django.contrib.gis.db.backends.postgis' ...}
  • Modify my app models.py to import models from django.contrib.gis.db, instead of django.db

Any guess what I'm missing?

like image 477
klautern Avatar asked Feb 23 '16 11:02

klautern


3 Answers

I had the same issue i installed the osgeo and then navigated to the missing libraries

> # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR =
> os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> TEMPLATE_DIR=os.path.join(BASE_DIR,'templates')

and these were the missing libraries for me:

 GDAL_LIBRARY_PATH = r'C:\OSGeo4W64\bin\gdal204.dll'
 GEOS_LIBRARY_PATH=r'C:\OSGeo4W64\bin\geos_c.dll'
like image 194
MoShamroukh Avatar answered Nov 05 '22 18:11

MoShamroukh


I had the same issue. I ran pip install gdal, which showed error messages about a libffi library missing on my system. After installing the correct library (libffi6 on AUR), I ran pip install gdal again and the issue was resolved.

like image 42
Ben Davis Avatar answered Nov 05 '22 17:11

Ben Davis


Run this command

sudo apt-get install binutils libproj-dev gdal-bin

This is described in this documentation

like image 41
Amir Avatar answered Nov 05 '22 18:11

Amir