I have QGIS installed (on Windows) and can import this line from the QGIS Python console:

from osgeo import gdal

When I try the import in a python file it doesn't work

Traceback (most recent call last):
  File "C:/Users/xxx/loader.py", line 6, in <module>
    from osgeo import gdal
ImportError: No module named osgeo

How can I use the osgeo lib outside from qgis?

  • Have you tried repeating your steps using the OSGeo4W Shell command prompt? Type in python and enter the path to your python script.
    – Joseph
    Commented Apr 7, 2015 at 12:24
  • Please follow the steps indicated at gis.stackexchange.com/questions/129959/… and let me know if it worked. Commented Apr 7, 2015 at 18:15

1 Answer 1


i don't recall all the steps i used, but with the anaconda distro, i placed a text file (something like qgislibs.pth) within my anaconda directory (or you default python install) - within the text file, include the path to your osgeo4w site packages - probably like C:\OSGeo4W64\apps\Python27\Lib\site-packages\

i think i also had to include a path in the system environment variables to point to the gdal binaries - something like C:\OSGeo4W\bin

i doubt that's fool proof everywhere, but it's working for me.

Your Answer

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

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