TransWikia.com

Installing GDAL with Anaconda

Geographic Information Systems Asked by triphook on December 14, 2020

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 "<stdin>", line 1, in <module>
  File "C:UsersJhookAppDataLocalContinuumminiconda3libsite-packagesgdal.py", line 2, in <module>
    from osgeo.gdal import deprecation_warn
  File "C:UsersJhookAppDataLocalContinuumminiconda3libsite-packagesosgeo__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:UsersJhookAppDataLocalContinuumminiconda3libsite-packagesosgeo__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
  File "C:UsersJhookAppDataLocalContinuumminiconda3libimp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:UsersJhookAppDataLocalContinuumminiconda3libimp.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?

4 Answers

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

Correct answer by user2856 on December 14, 2020

Like everyone said there seems to be an incompatibility issue. Creating a new environment solved the problem. This worked for me

Go to anaconda navigator --> environments --> Create --> GDAL Go to anaconda prompt --> activate GDAL --> conda install gdal

Hope this will do. But you have to install other libraries again in this new environment.

Answered by veda Lu on December 14, 2020

The following works reliably for me Ubuntu 20.04:

conda update conda    
sudo apt-get install libgdal-dev gdal-bin

export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal

# check gdal version with 
gdal-config --version

echo '
name: raster-pipeline
channels:
- defaults
dependencies:
- python=3.7.*
- cython
- numpy
- ipython
- libspatialindex
- libgdal=USE_GDAL_VERSION
- gdal=USE_GDAL_VERSION
- pip
- pip:
  - numpy>=1.18.5
  - GDAL==USE_GDAL_VERSION
  - pyproj>=2.6.1.post1
  - rasterio>=1.1.5
' > raster_pipeline.yml
  
conda env create -f raster_pipeline.yml -v 
 
conda activate raster_pipeline 
python -c "from osgeo import gdal"
conda deactivate 

Answered by mmann1123 on December 14, 2020

I've spent the day with that issue, and for me what worked was to install from wheels, as detailed on that video: https://www.youtube.com/watch?v=4ybddFC80fU

It is pretty simple. The only thing I had to change was to also install Fiona from wheel first, otherwise I had an error saying "a GDAL API version must be specified...[]"

Answered by le page yannick on December 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP