Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Hi I asked this question in the regular Stack Exchange site (http://stackoverflow.com/questions/11336153/python-gdal-package-missing-header-file-when-installing-via-pip) before I realised this site. As this site it more appropriate, I'll ask it here too;

I'm trying to install gdal from pip pip install gdal inside a virtual environment (Ubuntu). It fails because it cannot find cpl_port.h

extensions/gdal_wrap.cpp:2853:22: fatal error: cpl_port.h: No such file or directory
compilation terminated

However GDAL is installed correctly and the header file is located at /usr/include/gdal/cpl_port.h. Is there some environment variable for GDAL that needs to be set in order for pip to find the header files?

share|improve this question

3 Answers

The problem with the pip installing gdal is that it only gets the bindings, not the entire library, so it can get tricky. One way to solve it is to use the pip command to download - but not install. Then you tweak the header location from the config file. Then you pip install that. meh.

I was having the same problem but realized that writing a fabric script to recompile gdal and generate the python bindings was going to take less time. You even get the benefit of filegdb with that. Go ahead and use tha gist I wrote or tweak it to your hearts content.

share|improve this answer

Τhe header files cannot be found on your local filesystem so you need to specify the include dirs when installing gdal via pip.

first download gdal:

pip install --no-install GDAL

then specify where the headers are:

python setup.py build_ext --include-dirs=/usr/include/gdal/

then install it:

pip install --no-download GDAL

Here's another way to install gdal python:

$ sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
$ sudo apt-get update
$ sudo apt-get install python-gdal

after that open IDLE:

from osgeo import gdal

and you're good to go!

share|improve this answer
Hi thanks for you answer but I really need a way to install via pip as I will be creating isolated environments using virtualenv during CI process. – kevin Jul 8 '12 at 22:26
what is the output when you run 'gdal-config --version' and 'gdal-config --libs' ? – nickves Jul 9 '12 at 9:40
GDAL v1.9.1. gdal-config --libs -> -L/usr/lib -lgdal – kevin Jul 9 '12 at 17:35
@nickves I am trying to install GDAL using virtualenvwrapper in Ubuntu, and when I try your first line: pip install --no-install GDAL, I get the error: __main__.gdal_config_error: [Errno 2] No such file or directory Any idea? – theJollySin Mar 23 at 18:36
Yes, It seems that gdal bindings are trying to find gdal-confing within your virtualenv, and it fails because it's not there. A possible solution (I haven't test it!) is to create a symbolic link of your gdal-config to your virtualenv directory ( ls -s /path/to/gdal/gdal-config /path-to-virtualenvs/your-env/bin/gdal-config ). – nickves Mar 25 at 18:50

While a while later, this provides the include path without having to bail out of pip installation: One can set the include path using an environment variable.

Assuming the headers are in /usr/include/gdal, issue an

export CPLUS_INCLUDE_PATH=/usr/include/gdal

before running pip.

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.