Q: gdal Import error: DLL Load Failed when executing gdal_calc.py I have the recent version of QGIs/GDAL installed.
If I try to execute gdal_calc.py, I get the following error message:
`Traceback (most recent call last):
File "C:\OSGeo4W64\apps\Python37\lib\site-packages\osgeo_init_.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\OSGeo4W64\apps\Python37\lib\importlib_init_.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 670, in _load_unlocked
File "", line 583, in module_from_spec
File "", line 1043, in create_module
File "", line 219, in _call_with_frames_removed
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\GDAL\gdal_calc.py", line 5, in 
from osgeo.utils.gdal_calc import *  # noqa
File "C:\OSGeo4W64\apps\Python37\lib\site-packages\osgeo_init_.py", line 32, in 
gdal = swig_import_helper()
File "C:\OSGeo4W64\apps\Python37\lib\site-packages\osgeo_init.py", line 31, in swig_import_helper
return importlib.import_module('gdal')
File "C:\OSGeo4W64\apps\Python37\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
E:\UniversitaetHD\WS 2020 - 2021\Seminar GIS\Gruppenarbeit\Dateien>PAUSE`
Seems like those problems to me:
ImportError: DLL load failed with error code when I try to import GDAL from the Python console
gdal ImportError in python on Windows
Unfortunately, none of these solutions work for me.
My system variables are already right configured:


While executing from osgeo import gdal in python, the same error message appears.
I installed the latest GDAL versions from here: https://www.gisinternals.com/release.php



A: This works for me:

*

*Download and install Python 3.7. I don't like "Program Files" much but in this test I used C:\Program Files\Python37.

*Install GDAL with the MSI installer. I used C:\Program Files\GDAL.

*Install GDAL Python bindings with the MSI installer. Use the Python37 location from point 1) and check that you have osgeo package in  C:\Program Files\Python37\Lib\site-packages\ after installation.

GDAL installer creates a shortcut into Start menu. Open the GDAL command prompt from there. The gdal_data should look like this
C:\Program Files\GDAL>set gdal_data
GDAL_DATA=C:\Program Files\GDAL\gdal-data

At this moment GDAL does not know where to find Python. For the session that was just opened it can be set with
C:\Program Files\GDAL>set path=%path%;"c:\program files\Python37"

For making the setting permanent edit PATH in this file
C:\Program Files\GDAL>more gdalshell.bat
@echo off
@echo Setting environment for using the GDAL Utilities.
set SDK_ROOT=%~dp0
set SDK_ROOT=%SDK_ROOT:\\=\%
SET "PATH=%SDK_ROOT%;%PATH%"
SET "GDAL_DATA=%SDK_ROOT%gdal-data"
SET "GDAL_DRIVER_PATH=%SDK_ROOT%gdalplugins"
SET "PROJ_LIB=%SDK_ROOT%projlib"
SET "PYTHONPATH=%SDK_ROOT%python"

When the Python path is set especially for the GDAL shell it does not have any effect on other applications that use Python.
Now it is possible to do couple of tests.
C:\Program Files\GDAL>python
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>>

This looks good.
C:\Program Files\GDAL>python gdal_calc.py
Traceback (most recent call last):
  File "gdal_calc.py", line 5, in <module>
    from osgeo.utils.gdal_calc import *  # noqa
  File "c:\program files\Python37\lib\site-packages\osgeo\utils\gdal_calc.py", line 58, in <module>
    import numpy
ModuleNotFoundError: No module named 'numpy'

Ok, numpy is missing so add it_:
C:\Program Files\GDAL>python -m pip install numpy
Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
  Downloading numpy-1.20.1-cp37-cp37m-win_amd64.whl (13.6 MB)
     |████████████████████████████████| 13.6 MB 3.3 MB/s
Installing collected packages: numpy

Notice: Because of special handling that Windows has for "Program Files" numpy may get installed into users settings. Therefore in might be better to install Python in step 1) into dedicated directory like c:\python37.
Now try gdal_calc again:
C:\Program Files\GDAL>gdal_calc.py
Usage: gdal_calc.py --calc=expression --outfile=out_filename [-A filename]
                    [--A_band=n] [-B...-Z filename] [other_options]

