19

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

4
  • 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? Commented May 15, 2011 at 16:28
  • I downloaded Python from 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
    Commented May 15, 2011 at 16:44
  • 1
    I solved the problem by installing the MSVC2008-compiled versions of gdal and the gdal-python bindings from 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
    Commented May 17, 2011 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. Commented Jul 27, 2018 at 11:46

7 Answers 7

21

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 :)
6
  • 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
    Commented Aug 26, 2014 at 10:57
  • 1
    @iamgin makes a good point. Also, that I know of, 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
    Commented Aug 5, 2015 at 13:56
  • 1
    The dyndns.org link does not work anymore, the site has moved to gisinternals.com Commented Aug 28, 2015 at 7:27
  • Fixed the link in the answer
    – avee
    Commented Aug 31, 2015 at 3: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
    Commented May 2, 2018 at 0:30
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!

2
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

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.

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

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.

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".

Not the answer you're looking for? Browse other questions tagged or ask your own question.