close

[Solved] GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found”

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found” in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found” Error Occurs?

Today I get the following error GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found” in python.

How To Solve GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found” Error ?

  1. How To Solve GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found” Error ?

    To Solve GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found” Error In my case (Windows10Pro+Python3.7.1), having the (automatically chosen) dll present was not enough, namely gdal111.dll.

  2. GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found”

    To Solve GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found” Error In my case (Windows10Pro+Python3.7.1), having the (automatically chosen) dll present was not enough, namely gdal111.dll.

Solution 1


I have found the following to work for windows:

  • Run python to check if your python is 32 or 64 bit.
  • Install corresponding OSGeo4W (32 or 64 bit) into C:\OSGeo4W or C:\OSGeo4W64:
    • Note: Select Express Web-GIS Install and click next.
    • In the ‘Select Packages’ list, ensure that GDAL is selected; MapServer and Apache are also enabled by default, may be unchecked safely.
  • Make sure the following is included in your settings.py: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']
  • Run python manage.py check to verify geodjango is working correctly.

Solution 2

In my case (Windows10Pro+Python3.7.1), having the (automatically chosen) dll present was not enough, namely gdal111.dll.

I realized that I also had gdal204.dll located at C:\OSGeo4W\bin and tried to “enrich” the list variable named lib_names with 'gdal204', at line 24 (regarding Windows NT shared libraries) of %PYTHON_ROOT%\Lib\site-packages\django\contrib\gis\gdal\libgdal.py, i.e.

#[...]
elif os.name == 'nt':
    # Windows NT shared libraries
    lib_names = ['gdal204', 'gdal202', 'gdal201', 'gdal20', 'gdal111', 'gdal110', 'gdal19']
#[...]            ^^^^^^^

No negative consequences for now.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read