Yes, installing GDAL in a venv is a doozy. Conveniently, I just wrote up the documentation on how to do so for my advisor's lab! While I am not savvy enough to pinpoint the exact cause of your error, I can give you a bunch of things to try to fix it.
First, ensure you have gdal installed on the host (i.e. not in a venv). I just run the following:
sudo apt-get install libgdal1i libgdal1-dev libgdal-dev
Now run gdal-config --version
to get the version that apt-get
provided you with. For example I get 1.11.3
Now, the easiest way in my experience to get the python bindings in a venv is using pygdal
. The trick is to get the right version! To do so, activate your virtual environment and run
pip install pygdal==1.11.3
but replace the version with whatever you got from gdal-config --version
. Note: you may get an error that says
Could not find a version that satisfies the requirement pygdal==1.11.3 (from versions: 1.8.1.0, 1.8.1.1, 1.8.1.2, 1.8.1.3, 1.9.2.0, 1.9.2.1, 1.9.2.3, 1.10.0.0, 1.10.0.1, 1.10.0.3, 1.10.1.0, 1.10.1.1, 1.10.1.3, 1.11.0.0, 1.11.0.1, 1.11.0.3, 1.11.1.0, 1.11.1.1, 1.11.1.3, 1.11.2.1, 1.11.2.3, 1.11.3.3, 1.11.4.3, 2.1.0.3) No matching distribution found for pygdal==1.11.3
If that happens, run the pip install
again but with the highest version that still matches. e.g. in this case you would run pip install pygdal==1.11.3.3
Once pygdal
has been successfully installed, you should be able to call
>>> from osgeo import gdal
Please let me know if anything fails and I'll do what I can to adjust my instructions. Also, if you need help with Proj.4, GEOS, or Cartopy, I have some experience there too.
pip install gdal==1.9
is your friend). For Debian-based systems you also needlibgdal-dev
installed. And then there's sometimes alsoCPPFLAGS
andLDFLAGS
. – Carditisgdal-dev
andgdal-bin
packages. Runningpip
withCFLAGS="-I/usr/include/gdal" pip install gdal
might also be necessary. – Carditis