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:


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:


I have replaced my user name with xxx throughout.

  • People seem to have problems with GDAL on Anaconda, see for example trac.osgeo.org/gdal/ticket/6831. – user30184 Mar 23 '17 at 21:16
  • Generally, I use Linux in my projects, however, I recently used gdal_merge.py in Windows and I got error. After some time, I remembered that Windows syntax is only with gdal_merge. I hope that it can help. – xunilk Mar 23 '17 at 22:36
  • It is gdal_merge.py even on Windows, but OSGeo4W delivers also gdal_merge.bat file that runs the python script as @python "%OSGEO4W_ROOT%\bin\gdal_merge.py" %* – user30184 Mar 24 '17 at 8:55

Try changing the line to simply:

import gdal

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

| improve this answer | |
  • I am on a new system now, and cannot test this answer. However, in my experience, GDAL should import with either import gdal or from osgeo import gdal. Also, I will note the error I cite above is not in my code, but rather in gdal_merge.py, which is part of the GDAL library. – Hub45 Apr 2 '19 at 19:56
  • It should, but I've had it fail to import with from osgeo import gdal because the system couldn't find osgeo. Editing gdal_merge.py is probably a bad idea but it's one I'd be tempted to try anyway. Hope your new system is working better! – meepit Apr 2 '19 at 20:02

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.