Search code examples
pythonpycharmcondagdalrasterio

rasterio and gdal DLL load fail in PyCharm


I have a conda environment with rasterio installed and a whole load of other libraries, including gdal.

When I do:

import rasterio

on jupyter notebook, it loads fine and I can utilise it's methods etc..

When I do exactly the same thing on PyCharm, with the same environment and interpreter, I can the following error:

from rasterio._base import gdal_version
ImportError: DLL load failed: The specified module could not be found.

I'm struggling to understand why this is the case, as it loads fine in jupter notebook.


Solution

  • I encountered the same problem as you and has finished solving it.

    First, You need to ensure that gdal version is still 2.x. If no, just remove it.

    conda remove rasterio gdal -y
    

    then reinstall gdal with specifying the installation version:

    conda install rasterio gdal=2 -y
    

    Then, you need add GDAL_DATA which containing a gcs.csv file to environment, for me in Windows:

    setx /m GDAL_DATA C:\Users\Admin\AppData\Local\ESRI\conda\envs\python3\Library\share\gdal
    

    reboot your computer, and import gdal before importing rasterio:

    In [1]: import rasterio
    ---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    <ipython-input-1-350e27267e59> in <module>
    ----> 1 import rasterio
    
    ~\AppData\Local\ESRI\conda\envs\python3\lib\site-packages\rasterio\__init__.py in <module>
         20             pass
         21
    ---> 22 from rasterio._base import gdal_version
         23 from rasterio.drivers import is_blacklisted
         24 from rasterio.dtypes import (
    
    ImportError: DLL load failed: 找不到指定的模块。
    
    In [2]: from osgeo import gdal
    
    In [3]: import rasterio