rasterio 和 gdal DLL 加载失败 PyCharm
rasterio and gdal DLL load fail in PyCharm
我有一个安装了 rasterio 的 conda 环境和一大堆其他库,包括 gdal。
当我这样做时:
import rasterio
在 jupyter notebook 上,它加载良好,我可以利用它的方法等。
当我在 PyCharm 上使用相同的环境和解释器执行完全相同的操作时,我可能会出现以下错误:
from rasterio._base import gdal_version
ImportError: DLL load failed: The specified module could not be found.
我很难理解为什么会这样,因为它在 jupter notebook 中加载得很好。
我遇到了和你一样的问题,已经解决了。
首先,您需要确保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
我有一个安装了 rasterio 的 conda 环境和一大堆其他库,包括 gdal。
当我这样做时:
import rasterio
在 jupyter notebook 上,它加载良好,我可以利用它的方法等。
当我在 PyCharm 上使用相同的环境和解释器执行完全相同的操作时,我可能会出现以下错误:
from rasterio._base import gdal_version
ImportError: DLL load failed: The specified module could not be found.
我很难理解为什么会这样,因为它在 jupter notebook 中加载得很好。
我遇到了和你一样的问题,已经解决了。
首先,您需要确保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