20

Trying to import gdal for Python 2.7.3 on Windows XP:

>>> import gdal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\gdal.py", line 2, in <module>
    from osgeo.gdal import deprecation_warn
  File "C:\Python27\lib\site-packages\osgeo\__init__.py", line 21, in <mo
    _gdal = swig_import_helper()
  File "C:\Python27\lib\site-packages\osgeo\__init__.py", line 17, in swit_helper
  _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified procedure could not be found.

Following suggestions from Installing GDAL with Python on windows? and elsewhere, here's what I've done so far:

The result is the same. Any other ideas about how to troubleshoot this?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
meetar
  • 431
  • 1
  • 3
  • 13
  • Did you install Python using OSGeo4W? – Nathan W Dec 31 '12 at 05:41
  • gdal19.dll is not in your path. Edit the environment variable and try again. Also, you should use the import: from osgeo import gdal. –  Dec 31 '12 at 15:43
  • @NathanW I had not - I installed 2.7.2 and tried again - no change. – meetar Dec 31 '12 at 16:26
  • @kyle gdal19.dll is in C:\OSGeo4W\bin which is in my path, and the result is the same when I try from osgeo. – meetar Dec 31 '12 at 16:28
  • Are you sure the versions match up for your python bindings and your osgeo install? I don't use windows that much. Can you check your gdal version to be sure it's 1.9.2: gdalinfo --version –  Dec 31 '12 at 17:47
  • Have you tried, in a command line, 'cd'ing to the site-packages/osgeo, launching python, and importing from the directory that gdal.py is in? This will let you know if the issue is PATH related. – Jay Laura Jan 08 '13 at 14:07
  • @JayLaura Yep - I'm in the dir, gdal.py and ogr.py are both sitting there looking at me, but I get the same error. – meetar Jan 08 '13 at 17:09
  • @kyle Interesting: gdalinfo --version throws an error: "Unable To Locate Component: This application has failed to start because ogdi_32b1.dll was not found. Re-installing the application may fix this problem." This leads me to this thread: http://comments.gmane.org/gmane.comp.gis.osgeo.osgeo4w/359 ... and I am on a 64-bit machine. (The 2nd line of gdal.py says it's 2.0.8, btw.) So maybe I'm out of luck. – meetar Jan 08 '13 at 18:07
  • I always use the gdal core and bindings from gisinternals.com/sdk (I use the development version though, 1.10dev). I am guessing 2.0.8 is the swig version that was used to create the bindings, not the gdal version. Open the osgeo4w shell (it sets the proper variables) and try to start python and import gdal –  Jan 08 '13 at 21:15
  • Old question, but it popped up on my feed today. I always use the binary install: http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal – blord-castillo Jul 20 '14 at 15:22

4 Answers4

23

Condensed procedure outlined in http://cartometric.com/blog/2011/10/17/install-gdal-on-windows/ for Windows 7, 32 Bits, to install GDAL PYTHON:

1) Install Python.

I installed Python 2.7.9 from https://www.python.org/

2) Install the GDAL binaries published by Tamas Szekeres.

First, I launched IDLE (Python GUI) noting the following values: "MSC v.1500" and "on win32":

enter image description here

In this link: http://www.gisinternals.com/release.php

Click in the magenta link of the below image:

enter image description here

Click in the magenta links of the below image for download and install gdal-111-1500-core.msi and GDAL-1.11.1.win32-py2.7.msi:

enter image description here

3) Append your environment Path variable

enter image description here

enter image description here

After click in Edit and search for Path, add:

;C:\Program Files\GDAL

DON'T FORGET the ; character before C:\Prog... and click OK three times:

enter image description here

4) Add the GDAL_DATA environment variable (one click in New for each variable: gdal-data and gdalplugins)

DON'T FORGET click OK three times:

enter image description here

enter image description here

5) Finally, perform a quick test to make sure everything worked.

Launch IDLE (Python GUI) and type from osgeo import gdal [Enter]:

enter image description here

I didn't get gdal ImportError in python on my Windows 7 system.

Note: import gdal is deprecated.

xunilk
  • 29,891
  • 4
  • 41
  • 80
  • 1
    I have tried with all above explained methods but it show error like this: ImportError: DLL load failed: The specified procedure could not be found. – Shiuli Pervin Sep 09 '16 at 08:24
  • I know that this method works for 7 and 8 Windows systems and python 2.7 with 32 bits. If you have different conditions you should carefully read in each link those that match in your own system. – xunilk Sep 09 '16 at 08:37
  • Thanks!I have recently windows 10 and I am screwed up. I installed in my office several computers it worked perfectly but not at home it is not working at all. I am hang up for several hours. Do you have any idea about it? – Shiuli Pervin Sep 09 '16 at 09:16
  • 1
    Same boat as you, @ShiuliPervin. It's a joke... so difficult to install this. I have literally spent all day trying to get gdal installed. Ridiculous! Apparently, though, you can do this with scipi http://www.hydro.washington.edu/~jhamman/hydro-logic/blog/2013/10/12/plot-netcdf-data/ as well as python-netcdf4 – pookie Nov 05 '16 at 21:44
  • I meant netcdf4-python: netcdf4-python https://github.com/Unidata/netcdf4-python – pookie Nov 05 '16 at 21:52
  • One problem may arise! ArcGIS installs python in the custom folder i.e. C:\Python27\ArcGIS10.3 you may need to show this path to the python bindings to be installed. – Learner Nov 17 '16 at 17:59
6

I recommend to place the path to GDAL in the PATH variable BEFORE(!!) the python path. In this way you avoid the fact that python can not find the necessary gdal.dlls

user3475430
  • 61
  • 1
  • 1
4

Similarly, I placed

C:\Program Files (x86)\GDAL;

at the very first in the Path of System Variables. Issue solved after 1 day of searching the web. Using Python 2.7.10, 32 bit, Windows 8.

jcjaimes
  • 41
  • 1
  • This solved my problem completely! I had Arc Desktop installed first and then installed gdal without an issue once I did this. – MoreMeowbell Mar 21 '20 at 04:14
  • This was an important step in the solution for me. For the rest, check the RobertH community wiki and my comments below it: https://gis.stackexchange.com/questions/2276/installing-gdal-with-python-on-windows/181833#181833 – Güray Hatipoğlu Mar 03 '22 at 12:28
0

If installing via whl you must install the visual-c redistribute to get gdal to work!

https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

jonincanada
  • 101
  • 1