[GIS] gdal_merge.py cannot import gdal in Windows 7 Anaconda GDAL Installation

gdalgdal-mergeimporterrorpython

I have an installation of GDAL through Anaconda that is mostly working, but it throws an ImportError whenever I run gdal_merge.py:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Continuum\Anaconda2\Scripts\gdal_merge.py", line 37, in <module>
    from osgeo import gdal
ImportError: No module named osgeo

I can import GDAL without error from my own scripts and commands, even within the above folder. Most of what I have read about similar issues is that they are usually related to the PATH environment variable, but as far as I can tell mine is pointing to all the right places:

C:\Users\xxx\AppData\Local\Continuum\Anaconda2;C:\Users\xxx\AppData\Local\Continuum\Anaconda2\Scripts;C:\Users\xxx\AppData\Local\Continuum\Anaconda2\Library\bin;

I have 64-bit Anaconda for Python 2.7 installed on a Windows 7 system. My version of GDAL is 2.1.0, which I installed with the conda install utility. I set and tested my GDAL_DATA environment variable, and believe it to be correct:

C:\Users\xxx\AppData\Local\Continuum\Anaconda2\Library\share\gdal

I have replaced my user name with xxx throughout.

Best Answer

Try changing the line to simply:

import gdal

I've had similar issues, that worked, no idea why.