Thursday 4 June 2015

python - Installing GDAL with Anaconda


I just did a fresh install of Anaconda3 and am trying to add GDAL/OGR. I've tried installing with both conda install gdal and conda install -c conda-forge gdal. In both cases, the install completes successfully, but when I import gdal, it raises the error:


Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Jhook\AppData\Local\Continuum\miniconda3\lib\site-packages\gdal.py", line 2, in
from osgeo.gdal import deprecation_warn
File "C:\Users\Jhook\AppData\Local\Continuum\miniconda3\lib\site-packages\osgeo\__init__.py", line 21, in
_gdal = swig_import_helper()
File "C:\Users\Jhook\AppData\Local\Continuum\miniconda3\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper

_mod = imp.load_module('_gdal', fp, pathname, description)
File "C:\Users\Jhook\AppData\Local\Continuum\miniconda3\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Jhook\AppData\Local\Continuum\miniconda3\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

I've found several workarounds out there, but most date back a few years and don't reflect more recent updates or changes. Is there a fix for this problem that works in 2018?



Answer



There seems to be an incompatibility between the latest version of conda and vs2015_runtime and conda-forge gdal.



If I create a conda-forge env and specify vs2015_runtime=14, everything works:


conda create -n testgdal -c conda-forge gdal vs2015_runtime=14 

activate testgdal

(testgdal) python

Python 3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 11:48:23) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.


>>> from osgeo import gdal
>>>

https://gis.stackexchange.com/a/291932


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...