ImportError: DLL load failed while importing _gdal: The specified module could not be found
Asked Answered
N

5

5

I have a python script that previously worked but that now throws the error:ImportError: DLL load failed while importing _gdal: The specified module could not be found. I am trying to upload a shapefile using fiona and originally the message read: ImportError: DLL load failed while importing _fiona: The specified module could not be found. I am using anaconda navigator as my IDE on windows 11.

I am aware that this is a question that has been asked before and I have read the answers to those questions. The solutions, however, hove not worked either due to my circumstance or my misinterpretation and action in following through with it. So my question is either how do I fix this, or, if it is not that simple, to better understand the problem.

I have looked inside the DLLs folder within the environment folder that I am using and there is nothing in there with name fiona, gdal or geopandas.

My attempts so far:

1. uninstall and re-install fiona gdal and geopandas (as I believe they are dependent).

2. update all libraries and anaconda to latest verions.

3. download Visual C++ Redistributable for Visual Studio 2015. Ran into issue during download as it was already installed on my computer, likely because it is a windows computer. Is it possible that this would help if i moved it to a different path/folder?

4. Uninstall and re-install anaconda navigator on cumputer. Re-create virtual environemt and import necessary libraries. result: error in line: import geopandas as gpd: ImportError: DLL load failed while importing _datadir: The specified module could not be found.

If there is a fix that I have not mentioned or if you suspect that I attempted one of the above fixed incorrectly because of my limited understanding of how python libraries are stored please make a suggestion!

Thank you

Nombles answered 3/3, 2022 at 22:59 Comment(2)
Was that linked to rasterio?Radie
My search for gdal dlls can help gis.stackexchange.com/a/456857/6295Pushkin
K
5

I was struggling badly with the same problem for the last couple of days. Using conda, I've tried everything I found on the internet such as:

conda update gdal

conda update -n base -c defaults conda

Creating new environments (over and over again).

Despite it's not recommended I even tried it with pip install... but no results.

At the end what worked for me was to create a new environment with Python version 3.6

conda create -n env python=3.6 gdal spyder

Let me know if it worked.

Koeppel answered 8/3, 2022 at 14:39 Comment(2)
you are a legend! It wokedNombles
Good to know that it worked! However, afterwards I had problems while installing other modules with conda. At the end I gave up and installed the last module I needed with pip. Could help if that happens to you as wellKoeppel
D
2

conda install gdal=3.0.2

This problem appears to be peculiar to newer versions of GDAL. The reason that HM_ft's trick of downgrading Python to version 3.6 worked was that it also caused GDAL to be downgraded to version 3.0.2.

FWIW - GDAL versions 3.4.1 and 3.5.2 have this issue for me. I am not sure of which intervening version (after 3.0.2 and up to 3.4.1) marks the point at which this problem appears.

(added info) I have created a GDAL problem report on this issue: https://github.com/OSGeo/gdal/issues/6569

Doable answered 21/10, 2022 at 18:48 Comment(0)
S
0

Try this sequence -

pip install wheel
pip install pipwin

pipwin install numpy
pipwin install pandas
pipwin install shapely
pipwin install gdal
pipwin install fiona
pipwin install pyproj
pipwin install six
pipwin install rtree
pipwin install geopandas

Source - https://mcmap.net/q/193374/-error-installing-geopandas-quot-a-gdal-api-version-must-be-specified-quot-in-anaconda

After this, try

pip install rasterio

if you wish to install rasterio also

Shelving answered 25/8, 2023 at 20:24 Comment(0)
C
0

I was also receiving the ImportError: DLL load failed while importing _gdal: The specified module could not be found. message. However, it turns out that the problem was not the absence of the GDAL DLL itself, but the absence of one of its dependencies. I supplied this dependency by installing the Visual Studio redistributable.

The error message is misleading, or at least confusing, in that it's not obvious that "the specified module" may refer to a dependency of the library that Python is trying to import. It seems that the ambiguity is not the fault of the Python implementation, however, but goes back to the Windows API.

Coaster answered 26/9, 2023 at 3:57 Comment(0)
O
0

I got the same error message when i tried to import gdal 3.4.3 with the following command:

from osgeo import gdal

ImportError: DLL load failed while importing _gdal: The specified procedure could not be found.

I installed gdal 3.4.3 into a fresh conda environment on Windows 10.

The error could be resolved by an update of the Microsoft Visual C++ 2015-2019 Redistributable from 14.28.29914 to 14.34.33130. The idea was hinted by the answer from E_Cross who did not have the redistributable at all. Also I reinstalled gdal into a new environment after the update of the redistributable.

Oceanography answered 29/1 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.