错误:将Gdal库与Python anaconda分发一起使用时

时间:2018-08-01 06:44:23

标签: python-3.x anaconda gdal

我正在使用带有蟒蛇分布的Python将卫星图像转换为数组以进行进一步处理。但是在使用.ReadAsArray()函数时,发生以下错误。我试图搜索该错误,但是没有合适的结果。我已经使用conda命令安装了所有内容。

from osgeo import gdal
    ds = gdal.Open('/home/alay/Desktop/Studies/2010/ndvi01jun2010.tif')
    band = ds.GetRasterBand(1)
    img= band.ReadAsArray()

执行上述代码后发生错误

ImportError                               Traceback (most recent call last)
~/.local/lib/python3.6/site-packages/osgeo/gdal_array.py in 
swig_import_helper()
     17         try:
---> 18             fp, pathname, description = imp.find_module('_gdal_array', [dirname(__file__)])
     19         except ImportError:

~/anaconda3/lib/python3.6/imp.py in find_module(name, path)
    296     else:
--> 297         raise ImportError(_ERR_MSG.format(name), name=name)
    298 

ImportError: No module named '_gdal_array'

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-eae4e7981f3a> in <module>()
----> 1 img= band.ReadAsArray()

~/.local/lib/python3.6/site-packages/osgeo/gdal.py in ReadAsArray(self, xoff, yoff, win_xsize, win_ysize, buf_xsize, buf_ysize, buf_type, buf_obj, resample_alg, callback, callback_data)
   2603         parameters should generally not be specified if buf_obj is specified. The array is returned"""
   2604 
-> 2605         from . import gdalnumeric
   2606 
   2607         return gdalnumeric.BandReadAsArray( self, xoff, yoff,

~/.local/lib/python3.6/site-packages/osgeo/gdalnumeric.py in <module>()
----> 1 from osgeo.gdal_array import *
      2 from numpy import *

~/.local/lib/python3.6/site-packages/osgeo/gdal_array.py in <module>()
     26                 fp.close()
     27             return _mod
---> 28     _gdal_array = swig_import_helper()
     29     del swig_import_helper
     30 else:

~/.local/lib/python3.6/site-packages/osgeo/gdal_array.py in swig_import_helper()
     18             fp, pathname, description = imp.find_module('_gdal_array', [dirname(__file__)])
     19         except ImportError:
---> 20             import _gdal_array
     21             return _gdal_array
     22         if fp is not None:

ModuleNotFoundError: No module named '_gdal_array'

0 个答案:

没有答案