2

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?

Joseph
  • 75,746
  • 7
  • 171
  • 282
gustavgans
  • 553
  • 4
  • 16
  • Have you tried repeating your steps using the OSGeo4W Shell command prompt? Type in python and enter the path to your python script. – Joseph Apr 07 '15 at 12:24
  • Please follow the steps indicated at http://gis.stackexchange.com/questions/129959/problem-with-import-qgis-core-when-writing-a-stand-alone-pyqgis-script/130102#130102 and let me know if it worked. – Germán Carrillo Apr 07 '15 at 18:15

1 Answers1

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.

fluidmotion
  • 1,874
  • 10
  • 16