{"id":22,"date":"2011-10-17T21:33:18","date_gmt":"2011-10-18T02:33:18","guid":{"rendered":"http:\/\/cartometric.com\/blog\/?p=22"},"modified":"2015-01-07T10:53:07","modified_gmt":"2015-01-07T16:53:07","slug":"install-gdal-on-windows","status":"publish","type":"post","link":"https:\/\/elrobis.com\/blog\/2011\/10\/17\/install-gdal-on-windows\/","title":{"rendered":"Install GDAL on Windows"},"content":{"rendered":"<p>Later posts on this blog will assume a working install of GDAL\/OGR, so\u00a0it&#8217;s prudent that I first demonstrate how to\u00a0get a fresh cut of GDAL\/OGR up-and-running on a\u00a0Windows system.<\/p>\n<p>Windows users have\u00a0a few options for installing GDAL (<a href=\"http:\/\/gis.stackexchange.com\/questions\/2276\/how-to-install-gdal-with-python-on-windows\" target=\"_blank\">see this question at gis.stackexchange<\/a>,which\u00a0will point you to\u00a0<a href=\"http:\/\/www.lfd.uci.edu\/~gohlke\/pythonlibs\/\" target=\"_blank\">Christoph Gohlke&#8217;s binaries<\/a> &#8211;scroll down to GDAL, and\u00a0<a href=\"http:\/\/trac.osgeo.org\/osgeo4w\/\" target=\"_blank\">the OSGeo4W Installer<\/a>, among other approaches). However, I&#8217;ll guide you through what works for me, which can be summarized as follows:<\/p>\n<p>1) Install Python<br \/>\n2) Install the GDAL binaries published by Tamas Szekeres<br \/>\n3) Append your environment Path variable<br \/>\n4) Add the GDAL_DATA environment variable<br \/>\n5) Finally, perform\u00a0a quick test to make sure everything worked.<\/p>\n<h2><strong>First, Install Python<\/strong><\/h2>\n<p>(For reference purposes, I\u00a0used version 2.7 for Win32):<\/p>\n<p>\u00b7 Start at the <a href=\"http:\/\/www.python.org\/\" target=\"_blank\">Python homepage<br \/>\n<\/a>\u00b7 At left,\u00a0find &#8220;Quick Links (2.7.2)&#8221; and select &#8220;Windows Installer&#8221;<br \/>\n\u00b7 Complete the download and start the installation<br \/>\n\u00b7 Accept the default options suggested by the installer<\/p>\n<p>Once Python is installed, launch IDLE (the built-in Python\u00a0IDE) to get specific details about your Python\u00a0installation:<\/p>\n<p>Follow Windows (Start)\u2192Programs\u2192Python 2.7\u2192IDLE (Python GUI)<\/p>\n<p>This figure emphasizes where to look:<\/p>\n<div id=\"attachment_23\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-7-PythonVersionInfo.png\"><img aria-describedby=\"caption-attachment-23\" loading=\"lazy\" class=\"size-medium wp-image-23\" title=\"Python Version Details Output in IDLE\" src=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-7-PythonVersionInfo-300x254.png\" alt=\"\" width=\"300\" height=\"254\" srcset=\"https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-7-PythonVersionInfo-300x254.png 300w, https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-7-PythonVersionInfo.png 707w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-23\" class=\"wp-caption-text\">Python Version Details Output in IDLE<\/p><\/div>\n<p>In this\u00a0case, I&#8217;m noting the following values:<br \/>\n\u00b7 &#8220;<strong>MSC v.1500<\/strong>&#8221;<br \/>\n\u00b7 &#8220;<strong>on win32<\/strong>&#8221;<\/p>\n<p>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&#8217;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.<\/p>\n<h2><strong>Next\u00a0Install the GDAL Binaries<\/strong><\/h2>\n<p>From\u00a0the <a href=\"http:\/\/www.gdal.org\/\" target=\"_blank\">GDAL homepage<\/a>, you&#8217;d navigate to Downloads\u2192Windows, and open <a href=\"http:\/\/www.gisinternals.com\/sdk\/\" target=\"_blank\">Tamas Szekeres&#8217; Windows binaries<\/a>. When Tamas&#8217; page loads, you&#8217;ll need to identify the proper download package for your version of Python, system bit-depth, and VC dependencies.<\/p>\n<blockquote><p><em><strong>Note<\/strong>: VC2005, VC2008, VC2010 refer to various dependencies upon C++ redistributable libraries. To get your very own, just Google &#8220;c++ redistributable&#8221; and pick up the most current release. Alternatively, if you want to play it uber-safe, download and install\u00a0<a href=\"http:\/\/www.microsoft.com\/visualstudio\/en-us\/products\/2010-editions\/visual-cpp-express\" target=\"_blank\">Visual C++ Express 2010<\/a>, and it will automagically qualify you for MSVC2010 builds\u00a0(which\u00a0equates to\u00a0the compiler used to build GDAL).<\/em><\/p><\/blockquote>\n<p>At\u00a0Tamas&#8217; site, do the following:<br \/>\n\u00b7 Scroll down to &#8220;GDAL and MapServer latest release versions&#8221;<\/p>\n<p>\u00b7 Find a release corresponding to both your\u00a0installed C++ redistributable library\u00a0AND\u00a0your\u00a0Python install. For instance, I used &#8220;release-1500-gdal-1-8-0-mapserver-6-0-0&#8221;, which corresponds to MSVC2008 (Win32) in the left column (note the figure).<\/p>\n<div id=\"attachment_24\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-8-MatchingGDAL.png\"><img aria-describedby=\"caption-attachment-24\" loading=\"lazy\" class=\"size-medium wp-image-24\" title=\"Finding the right GDAL binaries at gisinternals.com\" src=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-8-MatchingGDAL-300x205.png\" alt=\"\" width=\"300\" height=\"205\" srcset=\"https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-8-MatchingGDAL-300x205.png 300w, https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-8-MatchingGDAL.png 993w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-24\" class=\"wp-caption-text\">Finding the right GDAL binaries at gisinternals.com<\/p><\/div>\n<p>Selecting a release will take you to a new screen promoting a handful<br \/>\nof EXE and MSI files\u2014to use ogr2ogr, you&#8217;ll need two of these.<\/p>\n<p>\u00b7 Download and install <em>gdal-18-xxxx-core.msi<\/em> (where xxxx is 1310, 1400,<br \/>\n1500, or 1600, which\u00a0matches your Python setup). I recommend keeping the defaults while installing.<\/p>\n<p>\u00b7 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 <em>GDAL-1.8.0.win32-py2.7.msi<\/em>. Once again, run the installer and accept the defaults.<\/p>\n<blockquote><p><em><strong>Note<\/strong>: The GDAL installer should detect the Python instance <\/em><em>installed in the previous section (see Figure 1-9). If not, first review the <\/em><em>steps in the previous section to see if you omitted something (this\u00a0may <\/em><em>indicate the GDAL binaries do not match your installation of Python), otherwise select &#8220;Python from another location&#8221; and proceed cautiously.<\/em><\/p><\/blockquote>\n<div id=\"attachment_27\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-9-DetectPython1.png\"><img aria-describedby=\"caption-attachment-27\" loading=\"lazy\" class=\"size-medium wp-image-27\" title=\"The GDAL Python bindings installer should detect your Python installation.\" src=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-9-DetectPython1-300x259.png\" alt=\"\" width=\"300\" height=\"259\" srcset=\"https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-9-DetectPython1-300x259.png 300w, https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-9-DetectPython1.png 499w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-27\" class=\"wp-caption-text\">The GDAL Python bindings installer should detect your Python installation.<\/p><\/div>\n<h2>\u00a0Set the\u00a0Environment Variables<\/h2>\n<p>We&#8217;re nearly finished installing GDAL. In this section, we&#8217;ll configure the Windows environment variables (Path and GDAL_DATA)\u00a0so the GDAL\/OGR utilities will be\u00a0easily asccessible from the command line.<\/p>\n<h3>Append the Path Variable<\/h3>\n<p align=\"left\">First, append the GDAL installation directory onto the existing Path variable.\u00a0Do the following to edit the Path variable:<\/p>\n<p>\u00b7 Open the Control Panel (Start\u2192Control Panel), open System and select &#8220;Advanced System Settings&#8221;.<\/p>\n<blockquote><p><em><strong>Note<\/strong>: Alternatively, you can open the\u00a0Windows (Start) menu, right-click &#8220;Computer&#8221;, select Properties, then select &#8220;Advanced System Settings&#8221;, which I find easier.<\/em><\/p><\/blockquote>\n<p>\u00b7 Select &#8220;Environment Variables&#8221; (near the bottom).<\/p>\n<p>\u00b7 Find &#8220;Path&#8221; among the list options and select it.<\/p>\n<p>\u00b7 With &#8220;Path&#8221; selected, click the &#8220;Edit&#8221; button.<\/p>\n<p>\u00b7 When the Edit System Variable dialog appears, scroll to the end of the series, add a semi-colon (;)\u00a0to\u00a0separate the prior path from the new one you&#8217;re about to enter, then add your GDAL installation path. I added exactly this:\u00a0 <em>;C:\\Program Files (x86)\\GDAL<\/em><\/p>\n<p>\u00b7 Keep the Environment Variables dialog open for the next task.<\/p>\n<blockquote><p><em><strong>Warning<\/strong>: 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.<\/em><\/p>\n<div id=\"attachment_33\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-10-AppendPathVar.png\"><img aria-describedby=\"caption-attachment-33\" loading=\"lazy\" class=\"size-medium wp-image-33\" title=\"Appending the GDAL installation directory to the Path variable.\" src=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-10-AppendPathVar-300x160.png\" alt=\"\" width=\"300\" height=\"160\" srcset=\"https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-10-AppendPathVar-300x160.png 300w, https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-10-AppendPathVar-1024x547.png 1024w, https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-10-AppendPathVar.png 1214w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-33\" class=\"wp-caption-text\">Appending the GDAL installation directory to the Path variable. (THIS IMAGE IS FROM A WIN XP INSTALL! A WIN 7 install will likely require &quot;Program Files (x86)&quot;.<\/p><\/div><\/blockquote>\n<h3>Add the GDAL_DATA Variable<\/h3>\n<p>Next we&#8217;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.<\/p>\n<p>In Windows, create the GDAL_DATA variable as follows:<\/p>\n<p>\u00b7 In the Environment Variables dialog, click &#8220;New&#8221; (near the bottom).<\/p>\n<p>\u00b7 In the New Variable dialog, enter <em>GDAL_DATA<\/em> for the <em><strong>name<\/strong><\/em> value.<\/p>\n<p>\u00b7 For <strong><em>value<\/em><\/strong>, 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:\u00a0 <em>C:\\Program Files (x86)\\GDAL\\gdal-data<\/em><\/p>\n<blockquote><p><em>Once again,\u00a0confirm the gdal-data directory makes sense relative to your GDAL installation folder.<\/em><\/p><\/blockquote>\n<p>\u00b7 At this point, commit your changes by selecting &#8220;OK&#8221; on each dialog.<\/p>\n<div id=\"attachment_34\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-11-AddGdalDataVar.png\"><img aria-describedby=\"caption-attachment-34\" loading=\"lazy\" class=\"size-medium wp-image-34 \" title=\"Adding the GDAL_DATA variable.\" src=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-11-AddGdalDataVar-300x127.png\" alt=\"\" width=\"300\" height=\"127\" srcset=\"https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-11-AddGdalDataVar-300x127.png 300w, https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-11-AddGdalDataVar.png 347w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-34\" class=\"wp-caption-text\">Adding the GDAL_DATA variable. (Note! On Win 7 you&#39;ll probably need to use &quot;Program Files (x86)&quot;. I stole this image from my older WinXP tutorial.)<\/p><\/div>\n<h2><\/h2>\n<h3><span style=\"color: #ff0000;\">[Update 1 Oct, 2013] <\/span><\/h3>\n<h3><span style=\"color: #ff0000;\">Add the GDAL_DRIVER_PATH Variable<\/span><\/h3>\n<p>In the same way you added the GDAL_DATA variable, add a GDAL_DRIVER_PATH variable. <a href=\"http:\/\/www.mail-archive.com\/gdal-dev@lists.osgeo.org\/msg09754.html\" target=\"_blank\">This variable is necessary for the Python environment to locate various GDAL driver plugins<\/a>. 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&#8217;m on Win 7 at this point&#8211;note this is inconsistent with the screenshot, above).<\/p>\n<p>On my system, the gdalplugins directory is: <em>C:\\Program Files (x86)\\GDAL\\gdalplugins<\/em><\/p>\n<blockquote><p>For those who already have GDAL installed along with the Python bindings&#8211;If you&#8217;re trying to write custom scripts and you&#8217;re getting errors like <a href=\"http:\/\/osgeo-org.1560.x6.nabble.com\/Reading-a-NetCDF-file-with-python-not-recognised-as-a-supported-dataset-name-tt4979943.html#none\" target=\"_blank\">ERROR 4: ..does not exist ..is not recognized as a supported dataset name<\/a>, 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.<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2>Confirming a Successful GDAL\u00a0Installation<\/h2>\n<p>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\u00a0runtime arguments, and close, leaving some helpful usage hints in its wake.<\/p>\n<p>To test ogr2ogr in a Windows Command Prompt, do the following:<\/p>\n<p>\u00b7 Open the Windows (Start) menu, and at the bottom (&#8220;Search programs and files&#8221;), type <em>cmd<\/em> and hit Enter; this will open the Command Prompt.<\/p>\n<p>\u00b7 With the terminal open, type\u00a0<em>ogr2ogr<\/em> and hit Enter (see the image).<\/p>\n<p>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).<\/p>\n<div id=\"attachment_36\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-12-ConfirmOgr2Ogr1.png\"><img aria-describedby=\"caption-attachment-36\" loading=\"lazy\" class=\"size-medium wp-image-36\" title=\"Confirming a sucessful install by calling ogr2ogr.\" src=\"http:\/\/cartometric.com\/blog\/wp-content\/uploads\/2011\/10\/1-12-ConfirmOgr2Ogr1-300x207.png\" alt=\"\" width=\"300\" height=\"207\" srcset=\"https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-12-ConfirmOgr2Ogr1-300x207.png 300w, https:\/\/elrobis.com\/blog\/wp-content\/uploads\/2011\/10\/1-12-ConfirmOgr2Ogr1.png 678w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-36\" class=\"wp-caption-text\">Confirming a successful install by calling ogr2ogr.<\/p><\/div>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<h3><span style=\"color: #ff0000;\">[Update 27 Jan, 2014]<\/span><\/h3>\n<h3><span style=\"color: #ff0000;\">Change in testing\/confirming a successful install<\/span><\/h3>\n<p>My initial recommendation to just type &#8220;ogr2ogr&#8221;, which resulted in an error (which I warned you&#8217;d get), was confusing for several people. In hindsight, I agree it was a poor choice on my part. So I like this better:<\/p>\n<p>At the command prompt, type this:<\/p>\n<pre>gdalinfo --version<\/pre>\n<p>And the OGR module should respond with something like this:<\/p>\n<pre>C:\\Users\\elrobis&gt;gdalinfo --version\r\nGDAL 1.9.2, released 2012\/10\/08<\/pre>\n<p>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&#8217;t confirm that your environment is setup properly, if that stuff isn&#8217;t right, you&#8217;ll likely get errors when you actually apply GDAL or OGR to some task.<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>And voila! Assuming\u00a0you see\u00a0the Usage\/Help output, you should be good to go with a fresh GDAL\/OGR installation.<\/p>\n<p>Cheers, Elijah<\/p>\n<p><strong>[Edit 06.22.2012]<\/strong><\/p>\n<p>If you plan to create your own Python utility scripts with the OGR Python bindings, I further recommend the following Python libraries:<\/p>\n<p><a href=\"http:\/\/pypi.python.org\/pypi\/Shapely#downloads\">shapely<\/a>, <a href=\"http:\/\/www.lfd.uci.edu\/~gohlke\/pythonlibs\/#numpy\">numpy<\/a>, <a href=\"http:\/\/www.lfd.uci.edu\/~gohlke\/pythonlibs\/#pil\">Python Image Library (pil)<\/a>, <a href=\"http:\/\/www.lfd.uci.edu\/~gohlke\/pythonlibs\/#psycopg\">PostgreSQL Adapter (psycopg)<\/a>, <a href=\"http:\/\/www.lfd.uci.edu\/~gohlke\/pythonlibs\/#mysql-python\">MySQL Adaptor (mysql-python)<\/a>, <a href=\"http:\/\/geospatialpython.com\/2010\/11\/introducing-python-shapefile-library.html\">Python Shapefile Library (pyshp)<\/a>, <a href=\"http:\/\/pypi.python.org\/pypi\/pyDBF\/\">Dbase\/Xbase Adaptor Library (pydbf)<\/a>, <a href=\"http:\/\/www.lfd.uci.edu\/~gohlke\/pythonlibs\/#matplotlib\">matplotlib<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Later posts on this blog will assume a working install of GDAL\/OGR, so\u00a0it&#8217;s prudent that I first demonstrate how to\u00a0get a fresh cut of GDAL\/OGR up-and-running on a\u00a0Windows system. Windows users have\u00a0a few options for installing GDAL (see this question at gis.stackexchange,which\u00a0will point you to\u00a0Christoph Gohlke&#8217;s binaries &#8211;scroll down to GDAL, and\u00a0the OSGeo4W Installer, among [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,43],"tags":[7,8,9],"_links":{"self":[{"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/posts\/22"}],"collection":[{"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":16,"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":41,"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions\/41"}],"wp:attachment":[{"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elrobis.com\/blog\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}