Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#761 closed defect (fixed)

gdal-dev: ImportError: DLL load failed while importing _gdal

Reported by: andreaerdna Owned by: osgeo4w-dev@…
Priority: critical Component: Package
Version: Keywords:
Cc:

Description

The GDAL processing algorithms (e.g. GDAL Merge) with the latest QGIS 3.27.0-Master (qgis-dev 3.27.0-312-c6eca784ad-1 and gdal-dev 3.6.0-117-ebe17cf8fc-1) fail with the following error:

Traceback (most recent call last): 
File "C:\OSFB9F~1\apps\gdal-dev\lib\site-packages\osgeo\__init__.py", line 30, in swig_import_helper
return importlib.import_module(mname) 
File "C:\OSFB9F~1\apps\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level) 
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 565, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1173, in create_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: Impossibile trovare il modulo specificato. 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
File "C:\OSFB9F~1\apps\gdal-dev\Scripts\gdal_merge.py", line 5, in <module>
from osgeo.gdal import deprecation_warn 
File "C:\OSFB9F~1\apps\gdal-dev\lib\site-packages\osgeo\__init__.py", line 46, in <module>
_gdal = swig_import_helper() 
File "C:\OSFB9F~1\apps\gdal-dev\lib\site-packages\osgeo\__init__.py", line 42, in swig_import_helper
raise ImportError(traceback_string + '\n' + msg) 
ImportError: Traceback (most recent call last): 
File "C:\OSFB9F~1\apps\gdal-dev\lib\site-packages\osgeo\__init__.py", line 30, in swig_import_helper 
return importlib.import_module(mname) 
File "C:\OSFB9F~1\apps\Python39\lib\importlib\__init__.py", line 127, in import_module 
return _bootstrap._gcd_import(name[level:], package, level) 
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import 
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load 
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked 
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked 
File "<frozen importlib._bootstrap>", line 565, in module_from_spec 
File "<frozen importlib._bootstrap_external>", line 1173, in create_module 
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed 
ImportError: DLL load failed while importing _gdal: Impossibile trovare il modulo specificato. 

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().
Process returned error code 1

QGIS 3.22.11 and 3.26.3 in the same OSGeo4W installation are not affected.

Change History (7)

comment:1 by jef, 2 years ago

Summary: qgis-dev: ImportError: DLL load failed while importing _gdalgdal-dev: ImportError: DLL load failed while importing _gdal

comment:2 by jef, 2 years ago

Resolution: fixed
Status: newclosed

fixed in gdal-dev-3.6.0-118-ebe17cf8fc-1

comment:3 by andreaerdna, 2 years ago

The same issue still occurs on my system even updating gdal-dev to 3.6.0-119-f7c95ff1cf-1 and pdal to 2.4.3-2.

comment:4 by andreaerdna, 2 years ago

It seems adding

call "%OSGEO4W_ROOT%\bin\gdal-dev-env.bat"

in %OSGEO4W_ROOT%\apps\gdal-dev\Scripts\gdal_merge.bat

fixes the issue for GDAL Merge processing algorithm.

gdal_merge.bat:

@echo off
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\gdal-dev-env.bat"
python "%OSGEO4W_ROOT%\apps\gdal-dev\Scripts\gdal_merge.py" %*
Version 0, edited 2 years ago by andreaerdna (next)

comment:5 by andreaerdna, 2 years ago

Resolution: fixed
Status: closedreopened

comment:6 by jef, 2 years ago

Resolution: fixed
Status: reopenedclosed

comment:7 by andreaerdna, 2 years ago

Fixed in *gdal-dev* pacakges since version 3.6.0-120-569a800628-1.

Note: See TracTickets for help on using tickets.