I installed the "gdal-201-1800-core.msi" and "GDAL-2.1.2.win32-py3.4.msi" in WinPython. It looks like the gdal could run in python shell.( there is no error when type "import gdal" ). But I could not use any gdal function such as "GetRasterband()","ReadAsArray". what's wrong with the gdal?

import gdal

import ogr


AttributeError                            Traceback (most recent call last)
<ipython-input-4-a8404d484b8e> in <module>()
----> 1 band=file.GetRasterband(1)

AttributeError: 'NoneType' object has no attribute 'GetRasterBand'
  • That just means GDAL couldn't open your tif. Use gdal. UseExceptions() to see the error message.
    – user2856
    Dec 24, 2016 at 0:38
  • @Luke Such is the case! The tif without head file could not be open. Dec 30, 2016 at 1:54

2 Answers 2


You are not specifying the access conditions after the name of the dataset. See here. Try to mention if it is GA_ReadOnly or GA_Update, like

dataset=gdal.Open(filename,gdal.GA_ReadOnly)  # opening file

Also check if your raster is ok in any GIS software, and try to open with gdal any another raster.

  • 1
    GA_ReadOnly is the default access if not specified. gdal.Open(filename) is fine, assuming filename can be opened.
    – user2856
    Dec 30, 2016 at 4:19

Try using:

filename = 'D:/GeoNE/temp/m2000049.tif'

instead of what you have provided.

  • There is no more explanation to give because it's clear that the difference between the two codes is in the using of the forward slashes instead of backslashes and I used the verb "try" because I was not sure about the result. Then, I think your downvote was unnecessary.
    – mgri
    Dec 30, 2016 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.