Snappy/rasterio/gdal error when loading modules


I’ve been doing some snappy tutorials and am now trying to import rasterio for image display. When I try to do the import it gives this message:

ImportError                               Traceback (most recent call last)
<ipython-input-1-350e27267e59> in <module>
----> 1 import rasterio

C:\Miniconda3\envs\snap\lib\site-packages\rasterio\ in <module>
     20             pass
---> 22 from rasterio._base import gdal_version
     23 from rasterio.drivers import is_blacklisted
     24 from rasterio.dtypes import (

ImportError: DLL load failed: The specified module could not be found.

I’m using Jupyter lab and noticed in the bash window this message:

INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Incompatible GDAL 3.1.4 found on system. Internal GDAL 3.0.0 from distribution will be used.
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
Native library load failed.

I’m using Python 3.6, conda, Windows 10. I downgraded GDAL to 3.0.4 (the only one available in conda-forge) but it didn’t help. I followed other online posts and added .../env/DDLs path to my PATH. None of it has worked.

I don’t know if this is a rasterio problem or a snappy problem, so apologies if I’m posting in the wrong place. rasterio works fine in my other environments.

Edit: snappy works fine in this environment. I just can’t get snappy and rasterio to both work in the same environment.

This sort of problem is all to common for Windows. It is not unusual to have multiple GDAL installations, each a different GDAL version using different compiler runtime libraries. If Windows has loaded a GDAL DLL it may try to use the same DLL with a different GDAL, so the order in which differing GDAL versions are used can be a factor. You can check for this by running your script immediately after rebooting. Workarounds are often fragile due to updates or installs of other applications adding to the conflicts.

You should consider breaking your script into two parts, one using ESA SNAP snappy and the second using rasterio. Memory management differences between native python and ESA SNAP snappy mean it can be faster to use two simple scripts (and troubleshooting is usually faster).

1 Like

Great answer. Thanks.