[gdal-dev] Running GDAL through Python >= 3.8 on Anaconda - DLL load failed

Even Rouault even.rouault at spatialys.com
Wed Oct 13 03:43:47 PDT 2021


Pedro,

Did you try to "set USE_PATH_FOR_GDAL_PYTHON=YES" environment variable a 
suggested ?

Can you check if it set in OSGeo4W shell ?  ("echo 
%USE_PATH_FOR_GDAL_PYTHON%")

Wondering if we shouldn't enable that behavior automatically... although 
that we would go against upstream Python policy

Even

Le 13/10/2021 à 12:14, Pedro Venâncio a écrit :
> Hi all,
>
> I'm trying to create an Anaconda environment to run arosics, a 
> software that performs automatic subpixel co-registration of two 
> satellite image datasets.
>
> The environment seems correctly created, with GDAL working as expected 
> on the CLI:
> (arosics) PS C:\Users\PedroVenancio> gdalinfo --version
> GDAL 3.3.2, released 2021/09/01
>
> The problem is that when Python (versions >=3.8) calls GDAL, it gives 
> an error:
> (arosics) PS C:\Users\PedroVenancio> python
> Python 3.8.12 | packaged by conda-forge | (default, Oct 12 2021, 
> 21:22:46) [MSC v.1916 64 bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> from osgeo import gdal
> Traceback (most recent call last):
> File 
> "C:\Users\PedroVenancio\anaconda3\envs\arosics\lib\site-packages\osgeo\__init__.py", 
> line 21, in swig_import_helper
> return importlib.import_module(mname)
> File 
> "C:\Users\PedroVenancio\anaconda3\envs\arosics\lib\importlib\__init__.py", 
> line 127, in import_module
> return _bootstrap._gcd_import(name[level:], package, level)
> File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
> File "<frozen importlib._bootstrap>", line 991, in _find_and_load
> File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
> File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
> File "<frozen importlib._bootstrap>", line 556, in module_from_spec
> File "<frozen importlib._bootstrap_external>", line 1166, in create_module
> File "<frozen importlib._bootstrap>", line 219, in 
> _call_with_frames_removed
> ImportError: DLL load failed while importing _gdal: Impossível 
> localizar o procedimento especificado.
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File 
> "C:\Users\PedroVenancio\anaconda3\envs\arosics\lib\site-packages\osgeo\__init__.py", 
> line 37, in <module>
> _gdal = swig_import_helper()
> File 
> "C:\Users\PedroVenancio\anaconda3\envs\arosics\lib\site-packages\osgeo\__init__.py", 
> line 33, in swig_import_helper
> raise ImportError(traceback_string + '\n' + msg)
> ImportError: Traceback (most recent call last):
> File 
> "C:\Users\PedroVenancio\anaconda3\envs\arosics\lib\site-packages\osgeo\__init__.py", 
> line 21, in swig_import_helper
> return importlib.import_module(mname)
> File 
> "C:\Users\PedroVenancio\anaconda3\envs\arosics\lib\importlib\__init__.py", 
> line 127, in import_module
> return _bootstrap._gcd_import(name[level:], package, level)
> File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
> File "<frozen importlib._bootstrap>", line 991, in _find_and_load
> File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
> File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
> File "<frozen importlib._bootstrap>", line 556, in module_from_spec
> File "<frozen importlib._bootstrap_external>", line 1166, in create_module
> File "<frozen importlib._bootstrap>", line 219, in 
> _call_with_frames_removed
> ImportError: DLL load failed while importing _gdal: Impossível 
> localizar o procedimento especificado.
>
> 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().
> I've reported this error in the arosics issue tracker 
> (https://git.gfz-potsdam.de/danschef/arosics/-/issues/66 
> <https://git.gfz-potsdam.de/danschef/arosics/-/issues/66>), but it 
> seems to be working as expected in some similar systems (windows 10).
>
> So I believe it can be some kind of conflict with other installations 
> on my machine. I've for instance OSGeo4W and everything works fine:
> C:\OSGeo4W>gdalinfo --version
> GDAL 3.3.1, released 2021/06/28
>
> C:\OSGeo4W>python
> Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 
> 64 bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> from osgeo import gdal
> >>> gdal
> <module 'osgeo.gdal' from 
> 'C:\\OSGeo4W\\apps\\Python39\\lib\\site-packages\\osgeo\\gdal.py'>
>
> Has anyone seen this kind of error? Any hints to overcome?
>
> Thank you very much!
>
> Best regards,
> Pedro
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
http://www.spatialys.com
My software is free, but my time generally not.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20211013/e2ddc0b5/attachment-0001.html>


More information about the gdal-dev mailing list