Sunday 31 January 2016

installation - GDAL install on Mac: pip doesn't see gdal.h


I'm trying to install GDAL on a Mac (macos 10.12.2). I downloaded the GDAL 2.1 Complete package from http://www.kyngchaos.com/software/frameworks (which installs GDAL 2.1.2), and successfully ran the installer. Now I'm trying to compile the Python bindings, using pip. In my bash_profile, I added lines for include paths (where the GDAL installer put them):


export CPLUS_INCLUDE_PATH=/Library/Frameworks/GDAL.framework/Versions/2.1/Headers
export C_INCLUDE_PATH==/Library/Frameworks/GDAL.framework/Versions/2.1/Headers
export LIBRARY_PATH=/Library/Frameworks/GDAL.framework/Versions/2.1/unix/lib

then I tried to compile the bindings with:


pip install gdal==2.1.2


but pip complained it could only find versions up to 2.1.0 ("No matching distribution found for gdal==2.1.2"). So I tried using 2.1.0 for the install:


pip install gdal==2.1.0

which got pip to attempt the install, but which eventually failed with:


fatal error: 'gdal.h' file not found
#include "gdal.h"
^
2 warnings and 1 error generated.
error: command '/usr/bin/clang' failed with exit status 1


Yet, the file gdal.h is located in the Header directory I set for my include paths.


I tried the advice given in the following questions:


Python GDAL package missing header file when installing via pip


Install GDAL python package in virtualenv on mac


but it did not fix my problem.


What should I do next?



Answer



As Luke says, the Python bindings are included in the GDAL Framework (you can use Suspicious Package, free, or Pacifist, shareware, to examine the content of the GDAL 2.1 Complete package)


enter image description here


And there is gdal-py2.7.pth path file witch is installed in a in the Apple Python site-packages folder and points to the precedent folder (/Library/Python/2.7/site-packages/gdal-py2.7.pth)



enter image description here


But there is a problem: the content of this file is


import sys; sys.path.insert(0,'/Library/Frameworks/GDAL.framework/Versions/1.11/Python/2.7/site-packages')

though it should be


import sys; sys.path.insert(0,'/Library/Frameworks/GDAL.framework/Versions/2.1/Python/2.7/site-packages')

Therefore, simply correct the gdal-py2.7.pth file.


Now if you want to compile yourself the Python bindings, download the GDAL 2.1.0 python module and


python setup.py build_ext -I/Library/Frameworks/GDAL.framework/Versions/2.1/Headers -L/Library/Frameworks/GDAL.framework/Versions/2.1/unix/lib -lgdal

python setup.py build
python setup.py install

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...