I wanted to be able to import OSR from GDAL on my Python 2.7 (Anaconda) Windows 7 64-bit. I installed OSGeo4W after reading this post and eventually I'd like to import osr

from osgeo import osr

However, I cannot find any osgeo or osr after installing osgeo.

The other option would be installing GDAL from here but it says that "Do not use together with OSGeo4W".

How can I import osr after installing OSGeo4W?

I downloaded 64 bit version under Quick Start for OSGeo4W Users from https://trac.osgeo.org/osgeo4w/wiki not from https://trac.osgeo.org/gdal/wiki/GdalOgrInPython. Perhaps that is causing the problem.

2 Answers 2


Because OSGeo4W installs its own local Python site, there are certain environment variables that must be set to use it. The simplest way to do this is by running the "OSGeo4W Shell" and then running python from the resulting command line. Alternatively, you can inspect the "OSGeo4W.bat" batch file in the root of your OSGeo install folder for ideas about how to roll your own script.

  • So I found "OSGeo4W.bat" and it has bunch of text in it. Should I modify this file? Is that what you mean by rolling the script? Thanks \@echo off rem Root OSGEO4W home dir to the same directory this script exists in call "%~dp0\bin\o4w_env.bat" rem List available o4w programs rem but only if osgeo4w called without parameters \@echo on \@if [%1]==[] (cmd.exe /k o-help) else (cmd /c "%*")
    – ahoosh
    Commented Jul 31, 2015 at 18:44
  • No. Simply run the file to get a command line where you can run your Python scripts or the interpreter. Understanding the script will help you if you ever want to automate the startup of a Python program.
    – Scro
    Commented Jul 31, 2015 at 18:47
  • Great. So after running the file, I see bunch of stuff like gdal_calc, gdal_edit, etc. and then "GDAL 1.11.2, released 2015/02/10". A command "C:\OSGeo4W64" shows up. I am trying to import ogr but I am not in Python environment. I guess I don't have any clue what to do with it!
    – ahoosh
    Commented Jul 31, 2015 at 18:51
  • I also don't see any sign of ogr or osr in OSGeo4W64 folder. There are stuff like grass and qgis, but not osr. Maybe I installed the wrong package?
    – ahoosh
    Commented Jul 31, 2015 at 18:55
  • Sorry if confusing. At the command prompt (after all the gdal_calc, gdal_edit stuff) you can enter the command python to use an interactive python session, or enter something like python myscript.py to run a script you have already written. (This assumes the script is in the current directory.)
    – Scro
    Commented Jul 31, 2015 at 19:01

So after installing OSGeo4W, another Python has been installed on my system. My previous Python was 2.7.10 and this new one (in OSGeo4W folder) was 2.7.5. So, I completely erased OSGeo4W package following this post and the new installed Python was removed as a result. Then, I followed instructions on this page exactly and managed to install osgeo package. It doesn't come with qgis and other softwares but I didn't need them anyways.

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.