12

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?

klautern
  • 129
  • 3
  • 7
  • 26

4 Answers4

9

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'
MoShamroukh
  • 785
  • 7
  • 7
5

Run this command

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

This is described in this documentation

Amir
  • 8,821
  • 7
  • 44
  • 48
1

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.

Ben Davis
  • 13,112
  • 10
  • 50
  • 65
  • Thank you! This fixed it, as Pacman updated libffi to version 8, but gdal needed version 7 from AUR. – peterhil Nov 10 '21 at 13:39
0

I found that my libgdal library was causing me issues and giving me this error.

I'm working in windows under a conda environment running Django 1.11 and GDAL 2.0. Changing GDAL and django versions didnt seem to fix anything. However, setting the libgdal version to 1.11.2 seemed to clear the error up for me.