9

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.

Flynnpc
  • 331
  • 2
  • 3
  • 11

4 Answers4

7

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.

  • how did you install gdal? – ziggy Feb 26 '18 at 20:53
  • @ziggy, these instructions are straightforward: https://docs.djangoproject.com/en/1.11/ref/contrib/gis/install/#windows – sean.hudson May 24 '18 at 20:38
  • this worked for me! also this one was super helpful https://gis.stackexchange.com/questions/246556/installing-geodjango-dependencies-on-windows-10-or-windows-server-2012-r2 – ziggy Feb 26 '19 at 21:55
  • This one solves the issue on Windows for 'gdal303' which is missing. Thank you for sharing, too bad it's invasive! – jlandercy Dec 16 '21 at 10:14
  • if PYTHONPATH is not defined, try looking in folder: `C:\Users\John Doe\AppData\Local\Programs\Python\Python310\Lib\site-packages\django\contrib\gis\gdal` – Roland Jul 21 '23 at 18:51
2

I had the same problem, and for me the issue was I had started my cmd shell before updating the PATH environment variable used to search for the GDAL library. I just had to restart my shell and everything worked.

1

This solution works 100%. Try this if you haven't yet.

First, download the GDAL wheel from Christoph Gohlke's Unofficial Windows Binaries for Python Extension Packages.

Make sure to check your python version by opening python in terminal. You will see an output like this :

Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

In the above lines the python version is 3.8.5 and its on 32 bit. So the package that I will have to choose from the link will be 'GDAL-3.3.3-cp38-cp38-win32.whl'. You should choose yours similarly.

After you do that just run

pip install whl/GDAL-3.3.3-cp38-cp38-win32.whl

After installling GDAL. Paste the following code into your settings.py file

import os
if os.name == 'nt':
    VENV_BASE = os.environ['VIRTUAL_ENV']
    os.environ['PATH'] = os.path.join(VENV_BASE, 'Lib\\site-packages\\osgeo') + ';' + os.environ['PATH']
    os.environ['PROJ_LIB'] = os.path.join(VENV_BASE, 'Lib\\site-packages\\osgeo\\data\\proj') + ';' + os.environ['PATH']

AND you are good to go.

Mazhar Ali
  • 328
  • 1
  • 3
  • 13
0

After trying many solutions, including reinstalling, adding to paths etc, I found this relatively simple solution which worked for me.

https://stackoverflow.com/a/49159195/3768552

takje
  • 2,630
  • 28
  • 47