Get gdal development libraries:
$ sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
$ sudo apt-get update
$ sudo apt-get install libgdal-dev
Create and activate a virtual environment:
$ virtualenv gdalenv
$ source gdal/bin/activate
Download GDAL:
(gdalenv) $ pip install --no-install GDAL
Specify where the headers are:
(gdalenv) $ cd /path/to/gdalenv/build/GDAL
(gdalenv) $ python setup.py build_ext --include-dirs=/usr/include/gdal/
Install GDAL:
(gdalenv) $ pip install --no-download GDAL
Done.
Here is my contribution on how to put all this in an ansible role, if this can help someone.
this is a YAML file holding the role tasks for installing GDAL in a virtual environment
file: path={{ GDAL_ENV_DIR }} state=directory owner={{ GDAL_OWNER }} group={{ GDAL_GROUP }} mode=0775
pip: name=virtualenv
command: virtualenv --python=/usr/bin/python2.7 {{ GDAL_ENV_DIR }} --no-site-packages creates={{ GDAL_ENV_DIR }}
sudo: no
apt: name={{ item }} state=latest update_cache=yes
with_items:
sudo: no
pip: name={{ item }} virtualenv={{ GDAL_ENV_DIR }} extra_args='--global-option=build_ext --global-option="-I/usr/include/gdal/"'
with_items: