Search code examples
djangopython-3.xgeodjango

how to fix the 'django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library'


I am trying to store location of stores in my django database, i tried installing geodjango for the purpose which gives me the above error.

i have installed python postgresql osgeow psycopg2 also modified the envirenment variables as per geodjango documentation

i tried installing gdal manually using -http://www.gisinternals.com/query.html?content=filelist&file=release-1911-x64-gdal-2-2-3-mapserver-7-0-7.zip the generic core components

my settings.py file-

import os
if os.name == 'nt':
    import platform
    OSGEO4W = r"C:\OSGeo4W"
    if '64' in platform.architecture()[0]:
        OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
    os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
    os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']


INSTALLED_APPS = [
...
'django.contrib.gis',
]

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'services',
        'USER': '*******',
        'HOST': 'localhost',
        'PASSWORD': '******',
        'PORT': '5434',
    }

when i run

python manage.py check

it gives me the error

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal202", "gdal201", "gdal20", "gdal111", "gdal110", "gdal19"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

i have already set the gdal ibrary path to gdal data directory, it still isn't working.

Please help with whatever's wrong above.

Also suggest if there is any other way to store locations in django database?


Solution

  • i simply switched to linux and it worked.Although the problem was somewhere there was a library that windows couldn't figure out,switching to linux solved the issue.