Python 使用 conda 安装 gdal?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33574902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:34:59  来源:igfitidea点击:

Install gdal using conda?

pythongdal

提问by DQ_happy

I used

我用了

conda install gdal

to install the GDAL packages. But I had the following error when importing the packages.

安装 GDAL 包。但是在导入包时出现以下错误。

>>> from osgeo import gdal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: dlopen(/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so, 2): Library not loaded: libgdal.20.dylib
  Referenced from: /Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so
  Reason: image not found
>>> from osgeo import ogr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: dlopen(/Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so, 2): Library not loaded: libgdal.20.dylib
  Referenced from: /Users/danqing0703/anaconda/lib/python2.7/site-packages/osgeo/_gdal.so
  Reason: image not found

What should I do to have GDAL imported in Python?

我应该怎么做才能在 Python 中导入 GDAL?

采纳答案by user1269942

For windows users (as of December 2015):

对于 Windows 用户(截至 2015 年 12 月):

conda install gdal
conda upgrade numpy

Installing gdal will downgrade numpy, so then upgrade it back up. I recently had occasion to use windows for a change and I was pleasantly surprised that gdal "works" easily now.

安装 gdal 会降级 numpy,然后再升级它。我最近有机会使用 Windows 进行更改,我惊喜地发现 gdal 现在很容易“工作”。

Windows+python+gis people worldwide should be celebrating this. (that gdal-python goes in easily on windows...not that windows is one step closer to linux ;) )

全世界的 Windows+python+gis 人都应该为此庆祝。(gdal-python 在 Windows 上很容易进入……并不是说 Windows 离 linux 更近了一步;))

回答by andschar

you can also use the channel conda-forge

你也可以使用通道conda-forge

conda install -c conda-forge gdal

as suggested on the anaconda website.

正如anaconda 网站上所建议的那样。

回答by Jim McManus

I used

我用了

conda install -c conda-forge gdal

On a Fedora 30 machine and it lead me down a path of library conflict hell!

在 Fedora 30 机器上,它让我走上了库冲突地狱的道路!

conda install gdal

worked on my first try

在我的第一次尝试中工作

回答by Saba Alipour

I had the same problem, and after several days trying different solutions, I found the problem in conflict between Anaconda version and python version! if you have both Python and Anaconda on your system, then uninstall the python and use anaconda prompt to run this: pip install gdal

我遇到了同样的问题,经过几天尝试不同的解决方案,我发现问题在 Anaconda 版本和 python 版本之间存在冲突!如果您的系统上同时安装了 Python 和 Anaconda,请卸载 Python 并使用 anaconda 提示符运行:pip install gdal