{"record":{"id":"e7be7a0fd2bc0d61","repo":"django/django","slug":"could-not-find-the-gdal-library-tried-s-is-g","errorCode":null,"errorMessage":"Could not find the GDAL library (tried \"%s\"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.","messagePattern":"Could not find the GDAL library \\(tried \"(.+?)\"\\)\\. Is GDAL installed\\? If it is, try setting GDAL_LIBRARY_PATH in your settings\\.","errorType":"exception","errorClass":"ImproperlyConfigured","httpStatus":null,"severity":"critical","filePath":"django/contrib/gis/gdal/libgdal.py","lineNumber":66,"sourceCode":"        \"gdal3.7.0\",\n        \"gdal3.6.0\",\n        \"gdal3.5.0\",\n        \"gdal3.4.0\",\n        \"gdal3.3.0\",\n    ]\nelse:\n    raise ImproperlyConfigured('GDAL is unsupported on OS \"%s\".' % os.name)\n\n# Using the ctypes `find_library` utility to find the\n# path to the GDAL library from the list of library names.\nif lib_names:\n    for lib_name in lib_names:\n        lib_path = find_library(lib_name)\n        if lib_path is not None:\n            break\n\nif lib_path is None:\n    raise ImproperlyConfigured(\n        'Could not find the GDAL library (tried \"%s\"). Is GDAL installed? '\n        \"If it is, try setting GDAL_LIBRARY_PATH in your settings.\"\n        % '\", \"'.join(lib_names)\n    )\n\n# This loads the GDAL/OGR C library\nlgdal = CDLL(lib_path)\n\n# On Windows, the GDAL binaries have some OSR routines exported with\n# STDCALL, while others are not. Thus, the library will also need to\n# be loaded up as WinDLL for said OSR functions that require the\n# different calling convention.\nif os.name == \"nt\":\n    from ctypes import WinDLL\n\n    lwingdal = WinDLL(lib_path)\n\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/gdal/libgdal.py#L48-L84","documentation":"Raised as ImproperlyConfigured at import time when ctypes.util.find_library() returned None for every candidate name in libgdal.lib_names (and GDAL_LIBRARY_PATH was not set). The list tried includes versioned names up to gdal3.13.0 / gdal313 on Windows; newer or differently-named builds will not be auto-discovered.","triggerScenarios":"GDAL is not installed; libgdal.so is present but not in the linker path (ldconfig not refreshed); a custom build installed to /opt or /usr/local without updating LD_LIBRARY_PATH; a new GDAL version whose soname is beyond the highest versioned name in lib_names; Windows where the DLL is not on PATH.","commonSituations":"Minimal Docker images (python:slim) missing libgdal; conda environments where GDAL lives under $CONDA_PREFIX/lib but the system loader does not look there; fresh GDAL upgrades (e.g. 3.14+) whose soname is not yet in Django's hardcoded list; Windows installs where GDAL was added but PATH was not restarted.","solutions":["Install GDAL system-wide: apt-get install -y libgdal-dev (Debian/Ubuntu) or dnf install gdal-devel (Fedora).","Set GDAL_LIBRARY_PATH in settings.py to the absolute path of libgdal.so (find it with gdal-config --libs or ldconfig -p | grep gdal).","Refresh the linker cache: sudo ldconfig, or ensure LD_LIBRARY_PATH includes the directory containing libgdal.so.","For conda, run inside the activated conda env so $CONDA_PREFIX/lib is on the loader path; on Windows add the GDAL bin dir to PATH and restart the shell."],"exampleFix":"# settings.py\n# before: GDAL not discoverable\n\n# after\nGDAL_LIBRARY_PATH = \"/usr/lib/x86_64-linux-gnu/libgdal.so\"","handlingStrategy":"validation","validationCode":"import ctypes.util, os\ndef gdal_is_loadable():\n    if os.environ.get('GDAL_LIBRARY_PATH') and os.path.exists(os.environ['GDAL_LIBRARY_PATH']):\n        return True\n    return any(ctypes.util.find_library(n) for n in ('gdal', 'GDAL'))\n# assert gdal_is_loadable() before importing django.contrib.gis","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bake GDAL into your base Docker image rather than installing it ad hoc.","Pin GDAL_LIBRARY_PATH in settings for reproducibility across environments.","Run ldconfig after installing libgdal so find_library can locate it.","Match the GDAL shared-library major version to what your Django expects."],"tags":["gdal","installation","environment","improperly-configured"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}