Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am developing some code in Python, and I want to use the GDAL/OGR python bindings. What is the minimum I need to install in order to use the GDAL and OGR python bindings?

What is the easiest way to install GDAL/OGR if I only want to use it from Python?
I'm looking for an answer that applies to both mac and windows.

GDAL is listed in the Python Package Index (PyPi) but I don't understand how to install its dependencies (libgdal and the header files for both libgdal and numpy). Maybe all I need to do is install numpy and then get libgdal somewhere, and if so, where? Does a windows install need the Windows Binaries in addition to libgdal and it's header files?

How can I ensure that I get the proper python bindings for my version of Python (2.5, 2.6, 2.7, 3)?
Must changes be made to the PATH environment variable in order to use GDAL and OGR from Python, or can everything be accessed through my site-packages folder and a typical import statement?

These questions are relevant to this question but do not answer it:
installing GEOS, PROJ, GDAL/OGR into a python virtualenv on Mac OS X
How to install GDAL with Python on windows?

I should note that FWTools, OSGeo4W, and kyngchaos offer ogr and gdal with python bindings and are excellent, but FWTools and OSGeo4W ship with their own python, rather than acting as libraries for an existing python installation, and the kyng chaos frameworks appear to be for OS X only.

Thanks!

share|improve this question
    
"kyng chaos frameworks appear to be for unix only." I think you misunderstand, they are for OS X. –  Sean May 12 '11 at 18:55
    
@Sean thanks, corrected –  BenjaminGolder May 12 '11 at 19:38
2  
See gis.stackexchange.com/questions/2276/… for the Windows Install. I'm personally a big fan of lfd.uci.edu/~gohlke/pythonlibs as they are Win64 and recent –  Mike T May 12 '11 at 22:28
    
I'm revisiting this 3 years later. In short, I can see that the problem is that python library installs tend to do a poor job of dealing with dependencies written in C. KyngChaos, FWTools, Anaconda, etc. all do the work of making platform specific C binaries that can be used with the version of Python they have. Basically no one has create a cross platform way to just pip install gdal and have it automatically include and compile all the necessary files from GDAL. It's expected that you will use some other means to create the GDAL binaries. –  BenjaminGolder Sep 4 at 22:14

7 Answers 7

Use this if you don't care ppa addition,

$ sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable

$ sudo apt-get update

$ sudo apt-get install python-gdal

share|improve this answer

First if you are on windows,then there are straight away installers,on the link told my friends above.But if you are on Linux this is the way for installing libgdal 1.11.

go to this page

http://packages.ubuntu.com/trusty/libgdal1h

download the required .deb file choosing your system architecture.

after downloading it go to downloaded directory and run this command

$ sudo dpkg -i libgdal1h_1.10.1+dfsg-5ubuntu1_amd64.deb

Now you will get an error telling dependencies are not installed. now type this command

$ sudo apt-get -f install

It installs all the dependencies automatically now re run the main installation command.

$ sudo dpkg -i libgdal1h_1.10.1+dfsg-5ubuntu1_amd64.deb

It will now install happily.Now we need to install developer libraries for gdal.

$ sudo apt-get install libgdal1-dev

export CPLUS_INCLUDE_PATH=/usr/include/gdal

export C_INCLUDE_PATH=/usr/include/gdal

Next if you have numpy,you can proceed to GDAL python library installation,else install numpy,for installing numpy and scipy on linux use

$ sudo apt-get install python-numpy python-scipy

now using pip install GDAL library

$ sudo pip install GDAL

share|improve this answer

If you are a windows user, you can find plenty usefull binaries , I am working with these and they are working very well... Good luck, cheers

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

    
Welcome to GIS@SE, it is better to provide more information with your answer, for example, specific binaries and steps for installation, this makes the information a lot more useful to the person asking the question as well as future people who view the question and answers. –  Mark C Aug 26 at 1:11

Only adding this because I tried using the kyng chaos tools, but on my Mac OS X machine I was able to very, very easily install this with Anaconda... conda install gdal. Posting in case anyone finds this again - I realize the original post is 3 years old.

share|improve this answer
    
I used Anaconda and it was simple for GDAL, but now I'd like to be able to run ogr2ogr -clipdst -105.53 39.9 -104.93 40.27 places.json ne_10m_admin_0_map_subunits.shp and it seems that I need to enable GEOS from a .configure file - any idea where Anaconda places this file? trac.osgeo.org/geos –  user28435 Sep 3 at 16:09
    
I appreciate the note, but this is similar to the KyngChaos binaries, in that it still doesn't allow you to use an existing python installation, and you must use the version of python shipped with Anaconda. –  BenjaminGolder Sep 4 at 22:11
    
I couldn't get the KyngChaos stuff to work though, hence adding the idea. But Anaconda lets you pick which version of Python to install, so...I don't know, I guess you have a reason for needing the other specific installation to be used? –  mmallek Sep 5 at 16:23

I had this exact problem when installing GDAL/OGR alongside the ArcGIS python install. My solution for windows was:

  1. Download binaries of gdal and python bindings from http://www.gisinternals.com/sdk/. This includes versions of the python bindings for different versions of python.
  2. Update the paths in the python file manually:

os.environ['PATH'] = "C:/Program Files (x86)/GDAL/;" + os.environ['PATH']

oldpaths = sys.path

sys.path = ["C:/Program Files (x86)/GDAL/python/",]

sys.path.extend(oldpaths)

from osgeo import ogr

from osgeo import osr

from gdalconst import * from osgeo import gdal

This isn't very pretty but allows you to mix different installations. You also know explicitly what you are loading.

share|improve this answer

I'm not aware of an easy way to install it on OS X, I think Kyng Chaos is the best thing going, as is OSGEO4W on the Windows front. The Python bindings are just wrappers to the actual C/C++ code, you can't get away without installing them either from source or through binaries.

Pip or easy_install can do the trick, depending on the Python version and system libraries present; for example here's the PyPI directory for Python 2.5. Getting GDAL installed consistently across multiple platforms and multiple versions of Python remains non-trivial, but in many ways that makes sense: its perhaps the one library which underlies most open source and many proprietary GIS software, and has a large number of data format dependencies below it.

share|improve this answer
    
As regards making sure things don't break, you might want to look at virtualenv and virtualenvwrapper to help keep things tidy. –  Jacques Tardie May 12 '11 at 4:04
    
PyPI has directories for 2.4 (win32 only, with GDAL 1.5, 1.6), 2.5 (mac/win32 with GDAL 1.5, 1.6) and 2.6 (win32 only, with GDAL 1.6). None have GDAL 1.7. If I understand the gist of the answer correctly, you're mainly saying it's not easy and that pip might work in some cases. Should I be looking into how to build it from source? –  BenjaminGolder May 12 '11 at 19:36
    
@BenjaminGolder: right, in my experience it can be tricky, especially if you're trying to support many platforms / and Python versions. Building from source takes more work up front but may be worth the time if you're trying to develop a consistent set of instructions. You may want to also ask your question on the GDAL list which is read by the developers themselves. –  scw May 15 '11 at 5:43

There are several tutorials on this site, including a way to get your environment set up. I use pyscripter over crimson editor, but either should work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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