GeoDjango on Windows: Try setting GDAL_LIBRARY_PATH in your settings
The issue ended up being a version mismatch between Django and GDAL. Django was not searching for the correct file name (gdal202.dll
in my case).
Fixing it required me to add str('gdal202')
to the following file on line 26:
(Python Root)\Lib\site-packages\django\contrib\gis\gdal\libgdal.py
Note that if you are working in a Virtual Environment, then Python Root
will actually be wherever that is ie: Users\YourName\Envs\project
If this issue reoccurs, you can look through your C:\OSGeo4W\bin
directory to figure out which gdalxxx.dll
it is that Django needs to search for.
In addition, make sure that you are using the 32-bit versions of Python and OSGeo4Win. Otherwise, you may see the same failure.
In addition to the previous comments. You might have a [WinError 127] The specified procedure could not be found.
This appears due to having multiple sqlite3.dll on your system. If the path hits those first a conflict appears for gdal202.
You can extend adam starrh answers by adding also a change of working directory.
#Set working directory to actual working directoy of gdal#This is required to prevent any conflicts with older SQLITE versions, #f.e. in python path #Prevents error in GDAL 202#BASE_WORKINGDIRECTORY to change it back later if you need toBASE_WORKDIRECTORY = os.getcwd()os.chdir(os.path.dirname(lib_path))# This loads the GDAL/OGR C librarylgdal = CDLL(lib_path)