Search code examples
djangogdalgeodjango

Why is command prompt returning a gdal not found error


I am trying to add geodjango to an already existing django project. I have installed everything that is request e.g postgressql proj geos e.t.c. I can't seem to install gdal on my system though. Everytime I try to run the project in local host it throws back a gdal not found error. I have tried using Osgeo4w, the .whl and the .msi file to try and install gdal. Can't seem to figure out what I'm doing wrong here.


Solution

  • If you use Windos, the easiest way I've found is:

    1. Install Gdal from whl, for examle: [https://www.lfd.uci.edu/~gohlke/pythonlibs/][1], if this link unavailable, the whl you need is not so difficult to find.
    2. Add to settings.py this code(change name of virtual env if need):
         OSGEO_VENV = Path(__file__).parents[1] / 'venv/Lib/site-packages/osgeo/'
         GEOS_LIBRARY_PATH = str(OSGEO_VENV / 'geos_c.dll')
         GDAL_LIBRARY_PATH = str(OSGEO_VENV / 'gdal204.dll')
         os.environ["PATH"] += os.pathsep + str(OSGEO_VENV)```