2

I am trying to run gdal in python using a script like this:

import os

gdal_path = r'"C:/Program Files/QGIS 3.22.1/apps/Python39/Scripts"'
gdal_calc_path = os.path.join(gdal_path, 'gdal_calc.py')

#commands come after

However, I am getting the error ```ImportError: DLL load failed while importing _gdal: The specified module could not be found.

On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH.
If gdalXXX.dll is in the PATH, then set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable
to feed the PATH into os.add_dll_directory().

what does this mean?

2 Answers 2

0

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.

-1

Install anaconda or miniconda

making a new enviroment

for example:

conda create --name name_env python=3.8 anaconda

then install packages

conda install -c conda-forge gdal, rasterio, geopandas

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.