Installing Python package
gdal into virualenv on Linux
GDAL provides nice toolkit for GEO related operations. However,
installing it to virtualenv on Linux is not trivial task.
This recipe describes, how to do that.
here I use lowercase
gdal for Python package and upper case
general system wide library.
- allow using osgeo libraries (installed via
gdal Python package) into
- allow installing on Linux Ubuntu
There are multiple methods for installation. One requires compilation
and takes few minutes more.
The other is using wheel package of
pygdal package and is very quick.
Anyway, to create the wheel package one needs to create it once and the creation includes the compilation step anyway.
GDAL packages and versions
GDAL is general C(++) based library for GEO related calculations.
GDAL utilities can be installed system wide what makes shared libraries
available, but does not install Python package itself.
GDAL comes in different versions and each Linux distribution may by
default install different version.
gdal requires compilation and is not trivial to install
on Linux based systems as it expects few environmental variables to be
set. This makes installation into virtualenv more difficult.
gdal version might assume different version of
GDAL and will fail
installing if expected version is not present in the system.
pygdal is alternative to
gdal, which installs exactly the
same stuff as
gdal, but does it in much more virtualenv friendly manner.
pygdal comes in versions reflecting related
GDAL version. So having
version 1.10.1 in the system you shall install
pygdal version 1.10.1.
gdal (as well as
pygdal) uses root python package named
osgeo and has set of submodules, one being
If needed, other than default versions of
GDAL can be installed and
used. This is out of scope of this description.
Wheel packages can be cross-compiled, this is also out of scope.
GDAL into system
GDAL shared libraries to be present, we must install
GDAL is not yet installed, calling
gdal-config will complain
and give you a hint how to follow up:
$ gdal-config --version
The program 'gdal-config' is currently not installed. You can install it by typing:
sudo apt-get install libgdal-dev
Follow the hint and install it:
$ sudo apt-get install libgdal-dev
Each distribution may use different version of
GDAL. To find out which
$ gdal-config --version
Now you know,
GDAL is installed and the version is 1.10.1 (the version
pygdal from source package (requires compilation)
pygdal is provided only in tar.gz package, which contains
package sources and requires compilation.
Assuming, the version of
1.10.1 and that our virtualenv is
$ pip install pygdal==1.10.1
It may take a while to complete, is it needs numpy, which may also
require some compilation. Just wait.
Check, it is installed:
$ pip freeze|grep pygdal
From now on, you may use osgeo package in your Python code as you like
in exactly the same manner as if you would install it by
Creating wheel package for
Note, that wheel packages must be created for exactly the same
architecture, namely must match:
- CPU architecture
- OS (Linux/Windows)
In our case, it must also match the version of
Following steps can be done in virtualenv or not, as you like.
First, make sure, wheel package is installed:
$ pip install wheel
Assuming, you have
GDAL installed and it has version 1.10.1:
$ pip wheel pygdal==188.8.131.52
and wait, until it completes.
After this, you shall find subdirectory wheelhouse and it shall contain
packages with extension `whl`:
$ ls wheelhouse
pygdal from wheel packages
Installation from wheel formatted packages is much faster (a second
compared to minutes), as it does not require compilation.
Note, that directory with wheel packages can have any name, we will use
just the name wheelhouse.
Activate virtualenv first.
Ensure, you have in wheelhouse directory both required wheel packages
GDAL is installed and the version matches version of
pygdal from wheel package:
$ pip install pygdal==184.108.40.206 -f wheelhouse
The -f wheelhouse shall point to the directory with whl files.
There is no need to install
numpy, it gets installed automatically.