Cartometric Blog

A scrapbook of GIS tricks, with emphasis on FOSS4G.

Install GDAL on Windows

with 33 comments

Later posts on this blog will assume a working install of GDAL/OGR, so it’s prudent that I first demonstrate how to get a fresh cut of GDAL/OGR up-and-running on a Windows system.

Windows users have a few options for installing GDAL (see this question at gis.stackexchange,which will point you to Christoph Gohlke’s binaries –scroll down to GDAL, and the OSGeo4W Installer, among other approaches). However, I’ll guide you through what works for me, which can be summarized as follows:

1) Install Python
2) Install the GDAL binaries published by Tamas Szekeres
3) Append your environment Path variable
4) Add the GDAL_DATA environment variable
5) Finally, perform a quick test to make sure everything worked.

First, Install Python

(For reference purposes, I used version 2.7 for Win32):

· Start at the Python homepage
· At left, find “Quick Links (2.7.2)” and select “Windows Installer”
· Complete the download and start the installation
· Accept the default options suggested by the installer

Once Python is installed, launch IDLE (the built-in Python IDE) to get specific details about your Python installation:

Follow Windows (Start)→Programs→Python 2.7→IDLE (Python GUI)

This figure emphasizes where to look:

Python Version Details Output in IDLE

In this case, I’m noting the following values:
· “MSC v.1500
· “on win32

Your values may be different than mine. For instance, you may have v.1400? Or maybe you installed 64-bit Python on a 64-bit system? Whatever you did, you’ll need to be consistent from here on out. Since these values will be important in the next step, you may want to keep the IDLE window open for a few minutes.

Next Install the GDAL Binaries

From the GDAL homepage, you’d navigate to Downloads→Windows, and open Tamas Szekeres’ Windows binaries. When Tamas’ page loads, you’ll need to identify the proper download package for your version of Python, system bit-depth, and VC dependencies.

Note: VC2005, VC2008, VC2010 refer to various dependencies upon C++ redistributable libraries. To get your very own, just Google “c++ redistributable” and pick up the most current release. Alternatively, if you want to play it uber-safe, download and install Visual C++ Express 2010, and it will automagically qualify you for MSVC2010 builds (which equates to the compiler used to build GDAL).

At Tamas’ site, do the following:
· Scroll down to “GDAL and MapServer latest release versions”

· Find a release corresponding to both your installed C++ redistributable library AND your Python install. For instance, I used “release-1500-gdal-1-8-0-mapserver-6-0-0″, which corresponds to MSVC2008 (Win32) in the left column (note the figure).

Finding the right GDAL binaries at gisinternals.com

Selecting a release will take you to a new screen promoting a handful
of EXE and MSI files—to use ogr2ogr, you’ll need two of these.

· Download and install gdal-18-xxxx-core.msi (where xxxx is 1310, 1400,
1500, or 1600, which matches your Python setup). I recommend keeping the defaults while installing.

· Next download and install the GDAL binaries for your version of Python (i.e. 2.6, 2.7, 3.1). Your choice should match the bit-depth and version of Python you installed in the first place. In keeping with my running example, I used GDAL-1.8.0.win32-py2.7.msi. Once again, run the installer and accept the defaults.

Note: The GDAL installer should detect the Python instance installed in the previous section (see Figure 1-9). If not, first review the steps in the previous section to see if you omitted something (this may indicate the GDAL binaries do not match your installation of Python), otherwise select “Python from another location” and proceed cautiously.

The GDAL Python bindings installer should detect your Python installation.

 Set the Environment Variables

We’re nearly finished installing GDAL. In this section, we’ll configure the Windows environment variables (Path and GDAL_DATA) so the GDAL/OGR utilities will be easily asccessible from the command line.

Append the Path Variable

First, append the GDAL installation directory onto the existing Path variable. Do the following to edit the Path variable:

· Open the Control Panel (Start→Control Panel), open System and select “Advanced System Settings”.

Note: Alternatively, you can open the Windows (Start) menu, right-click “Computer”, select Properties, then select “Advanced System Settings”, which I find easier.

· Select “Environment Variables” (near the bottom).

· Find “Path” among the list options and select it.

· With “Path” selected, click the “Edit” button.

· When the Edit System Variable dialog appears, scroll to the end of the series, add a semi-colon (;) to separate the prior path from the new one you’re about to enter, then add your GDAL installation path. I added exactly this:  ;C:\Program Files (x86)\GDAL

· Keep the Environment Variables dialog open for the next task.

Warning: Be sure to confirm your GDAL installation directory. I installed GDAL on Windows XP, but if you run a newer version of Windows, your installation path may be different from mine.

Appending the GDAL installation directory to the Path variable. (THIS IMAGE IS FROM A WIN XP INSTALL! A WIN 7 install will likely require "Program Files (x86)".

Add the GDAL_DATA Variable

Next we’ll add a new System Variable, GDAL_DATA, which helps the various GDAL utilities find the gdal-data folder. Without access to the files in the gdal-data folder, GDAL may have trouble recognizing some projections and coordinate systems, among other things.

In Windows, create the GDAL_DATA variable as follows:

· In the Environment Variables dialog, click “New” (near the bottom).

· In the New Variable dialog, enter GDAL_DATA for the name value.

· For value, enter the path to your gdal-data folder; it should be one level below your GDAL directory, which you can confirm by scouting the GDAL folder. I used:  C:\Program Files (x86)\GDAL\gdal-data

Once again, confirm the gdal-data directory makes sense relative to your GDAL installation folder.

· At this point, commit your changes by selecting “OK” on each dialog.

Adding the GDAL_DATA variable. (Note! On Win 7 you'll probably need to use "Program Files (x86)". I stole this image from my older WinXP tutorial.)

[Update 1 Oct, 2013]

Add the GDAL_DRIVER_PATH Variable

In the same way you added the GDAL_DATA variable, add a GDAL_DRIVER_PATH variable. This variable is necessary for the Python environment to locate various GDAL driver plugins. Like the gdal-data directory, the gdalplugins directory should be one level below your GDAL installation. Of course, confirm the path on your system. (I’m on Win 7 at this point–note this is inconsistent with the screenshot, above).

On my system, the gdalplugins directory is: C:\Program Files (x86)\GDAL\gdalplugins

For those who already have GDAL installed along with the Python bindings–If you’re trying to write custom scripts and you’re getting errors like ERROR 4: ..does not exist ..is not recognized as a supported dataset name, you may simply need to add this additional environment variable. This is especially true if you followed my tutorial for setting up GDAL on your system in the first place! In case of the latter, my apologies.

 

Confirming a Successful GDAL Installation

To confirm the availability of ogr2ogr, just open a new command terminal and attempt to call ogr2ogr. If your installation is successful, ogr2ogr will start running, fail to find any valid runtime arguments, and close, leaving some helpful usage hints in its wake.

To test ogr2ogr in a Windows Command Prompt, do the following:

· Open the Windows (Start) menu, and at the bottom (“Search programs and files”), type cmd and hit Enter; this will open the Command Prompt.

· With the terminal open, type ogr2ogr and hit Enter (see the image).

Because we added the GDAL installation directory to the Path variable, Windows will attempt to find a valid ogr2ogr executable in the GDAL folder. If all goes well your command prompt should resemble the following figure (the ogr2ogr command is highlighted).

Confirming a successful install by calling ogr2ogr.

————————

[Update 27 Jan, 2014]

Change in testing/confirming a successful install

My initial recommendation to just type “ogr2ogr”, which resulted in an error (which I warned you’d get), was confusing for several people. In hindsight, I agree it was a poor choice on my part. So I like this better:

At the command prompt, type this:

gdalinfo --version

And the OGR module should respond with something like this:

C:\Users\elrobis>gdalinfo --version
GDAL 1.9.2, released 2012/10/08

Assuming you get a version number and a release date, and not an error, you should have a clean install of GDAL/OGR to work with. Be warned, though, getting the version output doesn’t confirm that your environment is setup properly, if that stuff isn’t right, you’ll likely get errors when you actually apply GDAL or OGR to some task.

————————

And voila! Assuming you see the Usage/Help output, you should be good to go with a fresh GDAL/OGR installation.

Cheers, Elijah

[Edit 06.22.2012]

If you plan to create your own Python utility scripts with the OGR Python bindings, I further recommend the following Python libraries, which I ordered by their frequency in my own useage:

shapely, numpy, Python Image Library (pil), PostgreSQL Adapter (psycopg), MySQL Adaptor (mysql-python), Python Shapefile Library (pyshp), Dbase/Xbase Adaptor Library (pydbf), matplotlib

Written by elrobis

October 17th, 2011 at 9:33 pm

Posted in GDAL/OGR,Python

Tagged with , ,

33 Responses to 'Install GDAL on Windows'

Subscribe to comments with RSS or TrackBack to 'Install GDAL on Windows'.

  1. Thank you very much Elrobis. The instructions were straightforward and very helpful. I have been trying to install GDAL on my computer a while ago in vain. With your instructions, I definitely installed it.

    Thank you once again
    Alassane

    Alassane

    22 Jun 12 at 1:37 am

  2. That’s great, Alassane, thanks for the feedback. I’m glad the post benefitted you. Cheers! elrobis

    elrobis

    22 Jun 12 at 9:58 am

  3. Wonderful! you made it so simple.

    Farhat Abbas

    15 Aug 12 at 3:51 am

  4. Thanks Elrobis, for the straightforward instructions. They were very helpful to me.

    LSerra

    16 Nov 12 at 5:11 pm

  5. Libraries cannot be loaded in my computer.
    I set the path from PostgreSQL:
    C:\Program Files\PostgreSQL\9.1\gdal-data
    and variable name to
    GDAL_DATA,
    but no libraries got loaded.
    Please help me out.

    Thank you.

    SriRamaChandra

    17 Dec 12 at 4:18 am

  6. Thanks for the guide.Do you know how to add HDF4 support to this? This doesnt recognize the EOS HDF 4 files.

    Singh

    10 Jan 13 at 11:13 am

  7. Thank you so much. One of the best tutorials I have read in a while!

    asdf

    5 Mar 13 at 1:50 pm

  8. [...] am trying to install GDAL for Python 2.7. I have followed the instruction in the http://cartometric.com/blog/2011/10/17/install-gdal-on-windows/ link and went through step by step. I set in environment variables as recommended. When I want to [...]

  9. Thank you very much. Lots of information over here http://gis.stackexchange.com/questions/2276/how-to-install-gdal-with-python-on-windows
    But this was the simplest for what I wanted to do

    Luke

    3 Jun 13 at 12:38 am

  10. thanks a lot! it was just worked like a charm !

    geoendemics

    8 Oct 13 at 7:57 am

  11. At the very end, after typing ogr2ogr on the CMD screen, there was a “FAILURE: no target datasource provided”.
    -
    What did i do wrong? I’ve followed all the steps.

    Felipe

    24 Oct 13 at 10:02 pm

  12. Hi
    I’m also getting the message:
    “FAILURE: no target datasource provided”

    Does this mean that I have been unsuccesfull in the installation of gdal?

    Alex

    6 Nov 13 at 9:06 am

  13. Hey,
    I have the same problem:
    “FAILURE: no target datasource provided”
    What went wrong?

    hubert

    10 Dec 13 at 3:33 pm

  14. @hubert, it seems to me it worked. I’ll restate a remark in my original post. Please note the bit about it failing.. “If your installation is successful, ogr2ogr will start running, fail to find any valid runtime arguments, and close, leaving some helpful usage hints.” This post was just intended to assist with the installation of GDAL, not instruct on its usage. So based on the info you provided, I think you have it installed, now you just need to use it for something.

    elrobis

    27 Jan 14 at 8:59 am

  15. @Alex, please note my reply to hubert. You (probably) have GDAL installed correctly–it’s just not finding valid instructions and therefore throwing the error. Since folks don’t seem to gather that, I’ll change the post to recommend something less scary to confirm the install.

    elrobis

    27 Jan 14 at 9:03 am

  16. @Filipe, see my replies to hubert and Alex. My post notes that the simple “ogr2ogr” instruction, which doesn’t include any usage parameters, will result in a failure. But obviously this was a poor choice on my part. I’ll change the post to recommend having ogr2ogr output its version or something. I wish I’d thought of that initially. Sorry to recommend such a confusion manner of confirming everything was installed properly.

    elrobis

    27 Jan 14 at 9:06 am

  17. Has worked for me! Thank you very much.

    Edson

    4 Feb 14 at 5:39 am

  18. Thank you so much.
    You made this tutorial so simple.

    Marco Abbuonandi

    8 Feb 14 at 4:39 am

  19. This was invaluable. Thank you.

    Kasparas

    11 Feb 14 at 9:38 am

  20. Thank you very much, I’d never have been able to find this out by myself. One thing that confused me is that the core installer file is missing from the latest win32 1500 release (release-1500-gdal-1-10-1-mapserver-6-4-1), so I had to get an older release. Obviously, that’s not your fault though.

    Roger

    13 Feb 14 at 8:28 am

  21. Hi there,

    These are really useful instructions I have followed them however I am having trouble getting python to see the osgeo modules. Are you able to provide some instructions how to test python to make sure it is correctly configured? I ahve installed Python with ArcGIS and have a 32bit and 64bit installation on a 64bit machine.

    Regards,

    Marc

    Marc

    26 Feb 14 at 6:24 pm

  22. Hi Marc. The instructions in this post assume a vanilla Python installation (that is, beginning with a basic Python installer, which goes into a default directory). But you *should* be able to adapt these instructions to a different variety of Python installation. Because it’s possible to have multiple instances of Python installed on your system, you just need to make sure that all the components are getting wired to the right one. For example–when you install the GDAL binaries (see the 3rd screen grab in the blog), you can select “Python from another location”. I’ve never followed that route before, so I’m not sure what options it will give you, but you’d want to make sure and select the ArcGIS Python instance. I suspect the PATH, GDAL_DATA, and GDAL_DRIVER_PATH would not be different from the advice I provided in the post. You might also want to review the notes in this post, which discusses entanglement of the vanilla Python instance and the ArcGIS Python instance, and shows how I was able to install a Python library targeting a specific instance of Python. This might be important if, for instance, the “Python from another location” doesn’t automatically suggest the ArcGIS alternate instance. Please realize that I’m mostly guessing here, but it is a relatively educated guess.

    There is one warning I want to throw out there. Ultimately you’re desiring to “mutate” the Python instance running in support of ArcGIS. Fundamentally, I think it should be fine okay. However, there is a possibility of compromising the ArcGIS Python instance by introducing alternate influences. And I can promise you it’ll be much easier to destroy it than it will be to fix it after the fact! Having said that, however, I can certainly appreciate the interest in having ArcPy and all your other modules running out of a preferred Python instance—it just makes me wonder, if the ArcGIS Python instance is not sensitive, why would they give it its own installation directory and not expose it to the registry so that other Python modules would detect its presence? Know what I mean? ..like, almost as if they wanted to disguise it from 3rd party modules. If that’s the idea, it’s almost got to be for the purpose of keeping it clean and uncompromised by 3rd party stuff.

    Hopefully something in that rambling is helpful to you!

    Best, Elijah

    elrobis

    27 Feb 14 at 4:25 pm

  23. Great tutorial. Wouldn’t have been able to figure this out without it. Thanks much.

    bhickson

    20 May 14 at 3:31 pm

  24. This link was helpful and i have installed it correctly.

    Srinivasan

    30 Jun 14 at 9:25 am

  25. Thank a lot !, I used this for install gdal with python and used for my tesis. Maybe you want to add this to your tutorial:

    Testing/confirming a successful install working with Python

    At the command prompt, type this:

    python

    And Python should respond with something like this:

    Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win
    32
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>>

    In the promt (>>>) write: from osgeo import gdal

    If you dont get any error mesagge (just the promt again: >>>) then GDAL can be used in Python

    Cheers

    Yanina

    Yanina

    15 Jul 14 at 6:56 am

  26. Awesome work. Thank you so much!

    Darrick Roberts

    16 Jul 14 at 5:59 pm

  27. Got this running smooth as butter. Great work. Thanks!

    Phyn

    17 Jul 14 at 12:39 pm

  28. I have just spent a few days and many hours trying to install gdal on a Windows 7 computer that runs ArcGIS 10.0 and therefore Python 2.6 or 2.6.5. Your page got me the closest to a solution – thanks! The final thing I had to figure out is that the most recent gdal packages for my MSC/bit/etc. don’t include an installer for Python 2.6. To find that I had to go a bit back in time on the page with all the installers to here: http://gisinternals.com/sdk/PackageList.aspx?file=release-1500-gdal-1-10-1-mapserver-6-4-0.zip

    And I finally have gdal working on the computer! So relieved. I hope this comment helps someone else in my position.

    Maritza

    25 Aug 14 at 6:43 pm

  29. Thank you!!!

    Alan Stanton

    28 Aug 14 at 6:34 pm

  30. Thanks. It was very helpful for me.

    KD Nam

    31 Aug 14 at 7:56 am

  31. Hi,

    It took me 2 days to find a right website on how to use GDAL in simple terms. Even the GDAL.org doesnot provide the above steps. Thanks for the post. This helped me.

    Programmer

    24 Oct 14 at 10:25 am

  32. HI,
    thanks for the post.
    My problem is that the installation works, but I am unable to import modules in python. Any clue?

    Thanks,
    Daniel.

    Daniel

    5 Nov 14 at 10:12 am

Leave a Reply