GeoDjango could not find GDAL library in Windows 10

Flynnpc picture Flynnpc · Sep 20, 2017 · Viewed 7.8k times · Source

I am using Django 11.4 on Windows 10 and I am having problems when I try and migrate my models. I receive this error:

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal201", "gdal20", "gdal111", "gdal110", "gdal19")

I followed GeoDjango's installation instructions (https://docs.djangoproject.com/en/1.11/ref/contrib/gis/install/), but I am still having trouble. Everything I have found on this error says to change the system environment variables.

I installed OSGe4W and added GDAL_DATA = C:\OSGeo4W\share\gdal as well as PROJ_LIB= C:\OSGeo4W\share\proj.

I am not sure what else to try and I would appreciate any more insight.

Answer

Rob Goldsmith picture Rob Goldsmith · Oct 24, 2017

I fixed this by editing the libgdal.py file in %PYTHONPATH%\Lib\site-packages\django\contrib\gis\gdal and adding str('gdal202') to line 26 so it reads:

 lib_names = [str('gdal201'), str('gdal202'), str('gdal111'), str('gdal110'), str('gdal19')]

Depending on what version of GDAL you are using, you may need to add a different version number.