我刚刚全新安装了 Anaconda3,并尝试添加 GDAL/OGR。我尝试使用 conda install gdal
和 conda install -c conda-forge gdal
进行安装。在这两种情况下,安装都成功完成,但是当我导入 gdal 时,它会引发错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\user\AppData\Local\Continuum\miniconda3\lib\site-packages\osgeo\__init__.py", line 25, in <module>
_gdal = swig_import_helper()
File "C:\Users\user\AppData\Local\Continuum\miniconda3\lib\site-packages\osgeo\__init__.py", line 21, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
File "C:\Users\user\AppData\Local\Continuum\miniconda3\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\user\AppData\Local\Continuum\miniconda3\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
最佳答案
我认为这与此错误有关https://github.com/conda-forge/gdal-feedstock/issues/219
您应该使用虚拟环境(至少是为了快速测试不同的配置)
您可以尝试以下修复方法之一:
1)
从这个问题来看,vs2015_runtime 似乎有问题,它必须是 14 才能工作。所以检查你的vc2015运行库版本,如果太高可以降级。
conda create --name gdal_vs15_14 python=3.6.5
(在这里你大概可以看到它安装到环境中的vs2015_runtime是什么版本)
conda 激活 gdal_vs15_14
conda install -c conda-forge vs2015_runtime=14
conda install -c conda-forge gdal
2)
目前另一个简单的修复方法是使用 python 2.7(这当然不是最佳的,但至少目前对我来说是一个快速修复)
conda create --name gdal_py27 python=2.7
conda 激活 gdal_py27
conda install -c conda-forge gdal
关于python - 使用 Anaconda 安装 GDAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52063463/