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.
Some of the commands have been deprecated, namely
--no-install
(See: https://stackoverflow.com/questions/33207374/no-such-option-no-install)However, this can be still done in one line with only pip, The missing link is incorrect include flags for the build step but it seems the
--include-dirs
alone is not always sufficient.CFLAGS="-I /usr/include/gdal" CXXFLAGS="-I /usr/include/gdal" pip install GDAL==your.system.gdal.version
To determine installed GDAL, simply ask apt
apt show gdal-dev
and use the same version. Tested withGDAL-2.2.2
in ubuntugis-unstable