18

I am trying to install GDAL and Python on my Windows 7 workstation.

  • Python-version: 2.6.6
  • Gdal 1.8
  • (Visual Visual C++ Studio 2010 Express)

I followed the instructions at http://ucsb.pbworks.com/w/page/1936549/Using-GDAL-with-Python and added PYTHONPATH and the GDAL_DATA to my systems environment variables. Furthermore I modified my PATH variable by adding the GDAL binaries folder.

The GDAL Python bindings I downloaded from: http://vbkto.dyndns.org/sdk/PackageList.aspx?file=release-1600-gdal-1-8-mapserver-5-6.zip

"from osgeo import gdal" causes the following error-message:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    from osgeo import gdal
  File "C:\Python26\lib\site-packages\osgeo\__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\Python26\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

Thanks in advance, Martwig

Mario
  • 483
  • 1
  • 4
  • 15
  • Are you sure that those gdal python bindings are built with the same version of python and compiler as your python binary? (gdal's python bindings are swig-based, so they're compiled C extensions, not just python source files) Also, did you install gdal from the same source as the gdal python bindings you mentioned? – Joe Kington May 15 '11 at 16:28
  • I downloaded Python from http://www.python.org/download/releases/2.6.6/. And yes, I got gdal from the same source. Both, gdal and the bindings, are compiled with Visual Studio 2010 but I did not find out with which compiler Python 2.6.6 was build... – Mario May 15 '11 at 16:44
  • 1
    I solved the problem by installing the MSVC2008-compiled versions of gdal and the gdal-python bindings from http://vbkto.dyndns.org/sdk/. Furthermore I had to remove a backslash in my environment variables ("c:/Program Files/GDAL" instead of "c:/Program Files/GDAL/"). – Mario May 17 '11 at 11:16
  • The Best Solution in my case was switching from **WINDOWS** to Linux. - Because, I struggled with this problem for long time, moreover I found other problems relating to this. Instead of wasting time, It will be much productive to just switch OS. – Yerkebulan Duisebay Jul 27 '18 at 11:46

7 Answers7

20

To successfully load GDAL from python in Windows 7, I follow these steps, which should be quite generic:

  1. Install python of your choosing, I used v2.7.2 x64 downloaded from the official website
  2. Run python from command line to determine the compiler version used to build python (mine shows this message: Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32)
  3. Download the corresponding SDK from this link: http://www.gisinternals.com/release.php. Select the correct package for your python (if using the above configuration, then MSVC2008 x64 release link should be selected).
  4. From the subpage, download the following:
    • GDAL core components
    • Python bindings
  5. Install GDAL core components, add the installation dir to path, and add new environment variable 'GDAL_DATA' pointing to data subdirectory of GDAL installation.
  6. Install python bindings
  7. You should be profiting from them by now :)
avee
  • 766
  • 1
  • 13
  • 22
  • 7
    Yes, it works like a charm! Basically, it is VERY IMPORTANT, to match the compiler version of Python, the Python binding and the GDAL Core package. In my case, I downloaded version 1600 of Python binding and GDAL core package because they were the latest at this moment (08/2014). However, the compiling version of my Python was 1500. Additionally, I confused architectures: My laptop is a 64 bits machine, HOWEVER, my Python version is 32 bits. So I had to find Python binding packages + GDAL core packages for Win 32 bits architecture AND compiling version 1500. Both things. Hope this helps! :-) – Irene Aug 26 '14 at 10:57
  • 1
    @iamgin makes a good point. Also, [that I know of](http://cartometric.com/blog/2011/10/17/install-gdal-on-windows/), there are at least three (maybe more?) environment variables that need attention: `PATH` (`;C:\Program Files (x86)\GDAL`), `GDAL_DATA` (`C:\Program Files (x86)\GDAL\gdal-data`), and `GDAL_DRIVER_PATH` (`C:\Program Files (x86)\GDAL\gdalplugins`). These values may be different depending on your version of Windows and whether you changed any settings when you installed GDAL, so double-check that these disk addresses are valid before proceeding. – elrobis Aug 05 '15 at 13:56
  • 1
    The `dyndns.org` link does not work anymore, the site has moved to [gisinternals.com](http://www.gisinternals.com/) – Tom Bombadil Aug 28 '15 at 07:27
  • Fixed the link in the answer – avee Aug 31 '15 at 03:07
  • How do you know what release to choose? There is 1500, 1600, 1700 and so on. But nothing in the Python version indicate which release to choose. – Valachio May 02 '18 at 00:30
  • Have you checked your python build version by executing `python` from the command line? Read step no. 2. That said, I haven't been on Windows for quite some time, so things might have changed.. – avee May 07 '18 at 04:50
10

The step by step procedure is great. But I had the same issue.

This was caused because my PATH variable has other paths where a same named dll was used. If you put the c:\program files\gdal before the other paths in PATH, it works fine!

lode
  • 504
  • 6
  • 21
  • This worked for me too, on Windows XP, after following the instructions here http://www.gis.usu.edu/~chrisg/python/2009/docs/gdal_win.pdf – Sideshow Bob Sep 27 '12 at 15:13
  • Worked on win7x32 with Python 2.7 and [GDAL 9.1 + Python bindings from gisinternals.com](http://www.gisinternals.com/sdk/PackageList.aspx?file=release-1500-gdal-1-9-mapserver-6-2.zip) – csparpa Apr 02 '13 at 11:40
4

After searching and making many steps from the above answers with no result, i finally got install to Win7 gdal by using the installer from Unofficial Windows Binaries for Python Extension Packages

Just scroll down the page and find GDAL section and get your version installer.

3

solution for python 3.4, v.1600, Windows 10

make sure what your python version is

python -v
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32

so here you see that it's v.1600 and 32 bit. Then go here

http://www.gisinternals.com/query.html?content=filelist&file=release-1600-gdal-mapserver.zip

and download:

  1. gdal-201-1600-core.msi
  2. GDAL-2.1.0.win32-py3.4.msi
  3. Install these msi files

a. then make sure you DON'T GET OSGEO4W installed anywhere (just remove the folder completely if you got it installed).

b. go and edit your environment vars and include in PATH: C:\Program Files (x86)\GDAL; (include in the beginning!)

c. restart your python / virtualenv and IDE.

You should get everything working at this point

there are also bindings for python 2.7, 3.3, 3.1, other releases http://www.gisinternals.com/development.php

DmitrySemenov
  • 9,204
  • 15
  • 76
  • 121
2

I successfully installed gdal on 32 bit Windows from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal. I solved the "side by side" DLL error by installing this Microsoft Visual C++ 2008 Service Pack 1 Redistributable Package MFC Security Update.

Valentas
  • 2,014
  • 20
  • 24
0

Try this:

  • Add the GDAL core folder path to your PYTHONPATH variable
  • If using PyDev in Eclipse, force the global PATH variable to be include it using the PyDev interpreters section. You can also set PYTHONPATH here.

I got rid of this error after doing this. Funny thing was, calling that line that throws the import exception in a Python interactive shell worked before. Maybe we're all using PyDev.

tstittleburg
  • 91
  • 1
  • 5
0

I found that I needed to add the environment variables PATH, GDAL_DATA and GDAL_DRIVER_PATH (all three of them) to System variables NOT user variables for "your username".

ts91
  • 1
  • 1