I have installed GDAL and checked on the command line, it is working and when I run the gdal2tiles.py on the command line it works but when I run the same file gdal2tiles.py with python IDLE, I get "No module named 'osgeo'" error. Can you assist.
This sounds like you have multiple python installations, and GDAL is installed on one and not the other.
Try the following (which I have based upon this). Create a text file within your python installation site packages folder
usrlocal.pth. In this text file insert one line giving the path to your second python installation site packages folder which features the GDAL install, for example:
Another possibility is using easy_install from Python:
Preferably install numpy for array operations first:
For more information about easy_install/setup tools: https://setuptools.readthedocs.io/en/latest/easy_install.html