Rasterio和GDAL在PyCharm中的DLL加载失败

8

我有一个带有rasterio和许多其他库(包括gdal)的conda环境。

当我执行以下操作时:

import rasterio

在Jupyter Notebook上,它可以正常加载和使用其方法等。

当我在PyCharm上做完全相同的事情,使用相同的环境和解释器时,会出现以下错误:

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

我很难理解这是为什么,因为在Jupyter笔记本中它能够正常加载。


你使用的是哪个PyCharm版本? - user2235698
1个回答

3

我遇到了和你一样的问题,已经解决了。

首先,您需要确保gdal版本仍为2.x。如果不是,请将其删除。

conda remove rasterio gdal -y

然后重新安装GDAL并指定安装版本:
conda install rasterio gdal=2 -y

然后,您需要将包含gcs.csv文件的GDAL_DATA 添加到环境变量中,对于我的Windows计算机来说:

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

重新启动计算机,然后在导入rasterio之前先导入gdal:
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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接