Search code examples
djangoubuntugdalgeodjangodokku

Django / GeoDjango can't find the GDAL library on Ubuntu / Dokku


We're getting "django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library", GeoDjango's common installation issue.

Dev environment is Win10 and GDAL libraries were resolved following this answer on the same question for windows, which supplies filepaths directly. I now can't deploy because prod is Ubuntu 20.04 and that answer doesn't address how to resolve on Ubuntu.

I'm new to Ubuntu / Linux and I think I've installed GDAL with sudo apt install libpq-dev gdal-bin libgdal-dev following these instructions, but Django doesn't know how to find the libraries nor do I. This question mentions "GDAL_LIBRARY_PATH = '/usr/local/lib/libgdal.so.1.15.1'", but my "/usr/local/lib/" only includes the dirs of python3.8 and 3.9.

Also, unsure if relevant but I'm deploying on Dokku, and am unsure if containerizing things precludes Django from finding libs outside of Dokku's fancy ecosystem I don't well understand. This post is the only other post mentioning both Dokku and GDAL, and although it asks something unrelated its requirements.txt includes "GDAL==2.4.1". Could we somehow resolve this by supplying it in a similar way?

What simple thing am I missing or doing wrong?


Solution

  • Figured it out. Install the dokku-apt plugin and place a file named exactly "apt-packages" in the project's root. In that file list the packages you want installed, which in this case was:

    libpq-dev
    gdal-bin
    libgdal-dev