I wrote a code that projects a raster to a new coordinate system.

from osgeo import gdal

filename = r"C:\Users\rsl\Desktop\New folder\SN228122015_mosaic.tif"
input_raster = gdal.Open(filename)
output_raster = r"C:\Users\rsl\Desktop\New folder\SN228122015_mosaic_p.tif"

The code works great on pycharm when the interpreter is OSGEO, but when I run it when the interpreter is anaconda (like on jupyter notebook), I get this message error:

TypeError                                 Traceback (most recent call last)
<ipython-input-1-9021d776efc4> in <module>()
      4 input_raster = gdal.Open(filename)
      5 output_raster = r"C:\Users\rsl\Desktop\New folder\SN228122015_mosaic_p.tif"
----> 6 gdal.Warp(output_raster,input_raster,dstSRS='EPSG:4326')

C:\Users\rsl\Anaconda2\lib\site-packages\osgeo\gdal.pyc in Warp(destNameOrDestDS, srcDSOrSrcDSTab, **kwargs)
    548     if _is_str_or_unicode(destNameOrDestDS):
--> 549         return wrapper_GDALWarpDestName(destNameOrDestDS, srcDSTab, opts, callback, callback_data)
    550     else:
    551         return wrapper_GDALWarpDestDS(destNameOrDestDS, srcDSTab, opts, callback, callback_data)

TypeError: in method 'wrapper_GDALWarpDestName', argument 4 of type 'GDALWarpAppOptions *'

How can I make my code to work on the anaconda environment?

  • Are the gdal versions the same? You can access that information from the interpreter using gdal.VersionInfo() – Logan Byers Sep 18 '17 at 14:55

I had the same problem here, I found that we need to set the GDAL_DATA environment variable.

e.g. GDAL_DATA=C:\Python35\Lib\site-packages\osgeo\data\gdal


If setting the GDAL_DATA environment variable does not work then you may have to replace dstSRS='EPSG:4326' with gdal.WarpOptions(dstSRS='EPSG:4326') to get rid of the error that you are getting. You are supplying an keyword object where a gdal.WarpOptions object is needed.

Check out the docs for more information: https://gdal.org/python/osgeo.gdal-module.html#WarpOptions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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