[GIS] Error installing GDAL for Python on OSX

gdalosxpython

I'm trying to install GDAL for Python on my mac (OSX 10.9.2). I did:

>>> brew install GDAL

and got:

>>> 🍺  /usr/local/Cellar/gdal/1.11.3_1: 230 files, 33.1M

now:

>>> pip install GDAL

and I get a very long error log…

Collecting GDAL
  Using cached GDAL-2.0.1.tar.gz
Installing collected packages: GDAL
  Running setup.py install for GDAL ... error
    Complete output from command /Users/omrivolk/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/2x/sp5ytf0n11zf01vr0s11_mph0000gn/T/pip-build-slMMiq/GDAL/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/2x/sp5ytf0n11zf01vr0s11_mph0000gn/T/pip-02Yxar-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.5-x86_64-2.7
    copying gdal.py -> build/lib.macosx-10.5-x86_64-2.7
    copying ogr.py -> build/lib.macosx-10.5-x86_64-2.7
    copying osr.py -> build/lib.macosx-10.5-x86_64-2.7
    copying gdalconst.py -> build/lib.macosx-10.5-x86_64-2.7
    copying gdalnumeric.py -> build/lib.macosx-10.5-x86_64-2.7
    creating build/lib.macosx-10.5-x86_64-2.7/osgeo
    copying osgeo/__init__.py -> build/lib.macosx-10.5-x86_64-2.7/osgeo
    copying osgeo/gdal.py -> build/lib.macosx-10.5-x86_64-2.7/osgeo
    copying osgeo/gdal_array.py -> build/lib.macosx-10.5-x86_64-2.7/osgeo
    copying osgeo/gdalconst.py -> build/lib.macosx-10.5-x86_64-2.7/osgeo
    copying osgeo/gdalnumeric.py -> build/lib.macosx-10.5-x86_64-2.7/osgeo
    copying osgeo/ogr.py -> build/lib.macosx-10.5-x86_64-2.7/osgeo
    copying osgeo/osr.py -> build/lib.macosx-10.5-x86_64-2.7/osgeo
    running build_ext
    building 'osgeo._gdal' extension
    creating build/temp.macosx-10.5-x86_64-2.7
    creating build/temp.macosx-10.5-x86_64-2.7/extensions
    /usr/bin/clang -fno-strict-aliasing -I/Users/omrivolk/anaconda/include -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Wno-error=unused-command-line-argument-hard-error-in-future -Wno-error=unused-command-line-argument-hard-error-in-future -I../../port -I../../gcore -I../../alg -I../../ogr/ -I/Users/omrivolk/anaconda/include/python2.7 -I/Users/omrivolk/anaconda/lib/python2.7/site-packages/numpy/core/include -I/usr/local/Cellar/gdal/1.11.3_1/include -c extensions/gdal_wrap.cpp -o build/temp.macosx-10.5-x86_64-2.7/extensions/gdal_wrap.o
    clang: warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'?
    clang: warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'?
    warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]
    warning: unknown warning option '-Werror=unused-command-line-argument-hard-error-in-future'; did you mean '-Werror=unused-command-line-argument'? [-Wunknown-warning-option]
    extensions/gdal_wrap.cpp:2230:11: warning: explicitly assigning a variable of type 'int' to itself [-Wself-assign]
                        res = SWIG_AddCast(res);
                        ~~~ ^              ~~~
    extensions/gdal_wrap.cpp:2233:11: warning: explicitly assigning a variable of type 'int' to itself [-Wself-assign]
                        res = SWIG_AddCast(res);
                        ~~~ ^              ~~~
    extensions/gdal_wrap.cpp:4265:47: error: use of undeclared identifier 'GDALDatasetCreateLayer'; did you mean 'GDALDatasetShadow_CreateLayer'?
        OGRLayerShadow* layer = (OGRLayerShadow*) GDALDatasetCreateLayer( self,
                                                  ^~~~~~~~~~~~~~~~~~~~~~
                                                  GDALDatasetShadow_CreateLayer
    extensions/gdal_wrap.cpp:4264:28: note: 'GDALDatasetShadow_CreateLayer' declared here
    SWIGINTERN OGRLayerShadow *GDALDatasetShadow_CreateLayer(GDALDatasetShadow *self,char const *name,OSRSpatialReferenceShadow *srs=NULL,OGRwkbGeometryType geom_type=wkbUnknown,char **options=0){
                               ^
    extensions/gdal_wrap.cpp:4273:47: error: use of undeclared identifier 'GDALDatasetCopyLayer'
        OGRLayerShadow* layer = (OGRLayerShadow*) GDALDatasetCopyLayer( self,
                                                  ^
    extensions/gdal_wrap.cpp:4280:12: error: use of undeclared identifier 'GDALDatasetDeleteLayer'; did you mean 'GDALDatasetShadow_DeleteLayer'?
        return GDALDatasetDeleteLayer(self, index);
               ^~~~~~~~~~~~~~~~~~~~~~
               GDALDatasetShadow_DeleteLayer
    extensions/gdal_wrap.cpp:4279:19: note: 'GDALDatasetShadow_DeleteLayer' declared here
    SWIGINTERN OGRErr GDALDatasetShadow_DeleteLayer(GDALDatasetShadow *self,int index){
                      ^
    extensions/gdal_wrap.cpp:4306:8: error: use of undeclared identifier 'OGRERR_NON_EXISTING_FEATURE'
      case OGRERR_NON_EXISTING_FEATURE:
           ^
    extensions/gdal_wrap.cpp:4314:12: error: use of undeclared identifier 'GDALDatasetGetLayerCount'; did you mean 'GDALDatasetShadow_GetLayerCount'?
        return GDALDatasetGetLayerCount(self);
               ^~~~~~~~~~~~~~~~~~~~~~~~
               GDALDatasetShadow_GetLayerCount
    extensions/gdal_wrap.cpp:4313:16: note: 'GDALDatasetShadow_GetLayerCount' declared here
    SWIGINTERN int GDALDatasetShadow_GetLayerCount(GDALDatasetShadow *self){
                   ^
    extensions/gdal_wrap.cpp:4318:47: error: use of undeclared identifier 'GDALDatasetGetLayer'
        OGRLayerShadow* layer = (OGRLayerShadow*) GDALDatasetGetLayer(self, index);
                                                  ^
    extensions/gdal_wrap.cpp:4322:47: error: use of undeclared identifier 'GDALDatasetGetLayerByName'; did you mean 'GDALDatasetShadow_GetLayerByName'?
        OGRLayerShadow* layer = (OGRLayerShadow*) GDALDatasetGetLayerByName(self, layer_name);
                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~
                                                  GDALDatasetShadow_GetLayerByName
    extensions/gdal_wrap.cpp:4321:28: note: 'GDALDatasetShadow_GetLayerByName' declared here
    SWIGINTERN OGRLayerShadow *GDALDatasetShadow_GetLayerByName(GDALDatasetShadow *self,char const *layer_name){
                               ^
    extensions/gdal_wrap.cpp:4326:13: error: use of undeclared identifier 'GDALDatasetTestCapability'; did you mean 'GDALDatasetShadow_TestCapability'?
        return (GDALDatasetTestCapability(self, cap) > 0);
                ^~~~~~~~~~~~~~~~~~~~~~~~~
                GDALDatasetShadow_TestCapability
    extensions/gdal_wrap.cpp:4325:17: note: 'GDALDatasetShadow_TestCapability' declared here
    SWIGINTERN bool GDALDatasetShadow_TestCapability(GDALDatasetShadow *self,char const *cap){
                    ^
    extensions/gdal_wrap.cpp:4336:47: error: use of undeclared identifier 'GDALDatasetExecuteSQL'; did you mean 'GDALDatasetShadow_ExecuteSQL'?
        OGRLayerShadow* layer = (OGRLayerShadow*) GDALDatasetExecuteSQL(self,
                                                  ^~~~~~~~~~~~~~~~~~~~~
                                                  GDALDatasetShadow_ExecuteSQL
    extensions/gdal_wrap.cpp:4335:28: note: 'GDALDatasetShadow_ExecuteSQL' declared here
    SWIGINTERN OGRLayerShadow *GDALDatasetShadow_ExecuteSQL(GDALDatasetShadow *self,char const *statement,OGRGeometryShadow *spatialFilter=NULL,char const *dialect=""){
                               ^
    extensions/gdal_wrap.cpp:4343:5: error: use of undeclared identifier 'GDALDatasetReleaseResultSet'; did you mean 'GDALDatasetShadow_ReleaseResultSet'?
        GDALDatasetReleaseResultSet(self, layer);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
        GDALDatasetShadow_ReleaseResultSet
    extensions/gdal_wrap.cpp:4342:17: note: 'GDALDatasetShadow_ReleaseResultSet' declared here
    SWIGINTERN void GDALDatasetShadow_ReleaseResultSet(GDALDatasetShadow *self,OGRLayerShadow *layer){
                    ^
    extensions/gdal_wrap.cpp:4346:35: error: use of undeclared identifier 'GDALDatasetGetStyleTable'; did you mean 'GDALDatasetShadow_GetStyleTable'?
        return (OGRStyleTableShadow*) GDALDatasetGetStyleTable(self);
                                      ^~~~~~~~~~~~~~~~~~~~~~~~
                                      GDALDatasetShadow_GetStyleTable
    extensions/gdal_wrap.cpp:4345:33: note: 'GDALDatasetShadow_GetStyleTable' declared here
    SWIGINTERN OGRStyleTableShadow *GDALDatasetShadow_GetStyleTable(GDALDatasetShadow *self){
                                    ^
    extensions/gdal_wrap.cpp:4350:9: error: use of undeclared identifier 'GDALDatasetSetStyleTable'; did you mean 'GDALDatasetShadow_SetStyleTable'?
            GDALDatasetSetStyleTable(self, (OGRStyleTableH) table);
            ^~~~~~~~~~~~~~~~~~~~~~~~
            GDALDatasetShadow_SetStyleTable
    extensions/gdal_wrap.cpp:4348:17: note: 'GDALDatasetShadow_SetStyleTable' declared here
    SWIGINTERN void GDALDatasetShadow_SetStyleTable(GDALDatasetShadow *self,OGRStyleTableShadow *table){
                    ^
    extensions/gdal_wrap.cpp:4350:40: error: cannot initialize a parameter of type 'OGRStyleTableShadow *' (aka 'OGRStyleTableHS *') with an rvalue of type 'OGRStyleTableH' (aka 'void *')
            GDALDatasetSetStyleTable(self, (OGRStyleTableH) table);
                                           ^~~~~~~~~~~~~~~~~~~~~~
    extensions/gdal_wrap.cpp:4348:94: note: passing argument to parameter 'table' here
    SWIGINTERN void GDALDatasetShadow_SetStyleTable(GDALDatasetShadow *self,OGRStyleTableShadow *table){
                                                                                                 ^
    extensions/gdal_wrap.cpp:4353:12: error: use of undeclared identifier 'GDALDatasetStartTransaction'; did you mean 'GDALDatasetShadow_StartTransaction'?
        return GDALDatasetStartTransaction(self, force);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
               GDALDatasetShadow_StartTransaction
    extensions/gdal_wrap.cpp:4352:19: note: 'GDALDatasetShadow_StartTransaction' declared here
    SWIGINTERN OGRErr GDALDatasetShadow_StartTransaction(GDALDatasetShadow *self,int force=FALSE){
                      ^
    extensions/gdal_wrap.cpp:4356:12: error: use of undeclared identifier 'GDALDatasetCommitTransaction'; did you mean 'GDALDatasetShadow_CommitTransaction'?
        return GDALDatasetCommitTransaction(self);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
               GDALDatasetShadow_CommitTransaction
    extensions/gdal_wrap.cpp:4355:19: note: 'GDALDatasetShadow_CommitTransaction' declared here
    SWIGINTERN OGRErr GDALDatasetShadow_CommitTransaction(GDALDatasetShadow *self){
                      ^
    extensions/gdal_wrap.cpp:4359:12: error: use of undeclared identifier 'GDALDatasetRollbackTransaction'; did you mean 'GDALDatasetShadow_RollbackTransaction'?
        return GDALDatasetRollbackTransaction(self);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
               GDALDatasetShadow_RollbackTransaction
    extensions/gdal_wrap.cpp:4358:19: note: 'GDALDatasetShadow_RollbackTransaction' declared here
    SWIGINTERN OGRErr GDALDatasetShadow_RollbackTransaction(GDALDatasetShadow *self){
                      ^
    extensions/gdal_wrap.cpp:4361:294: error: unknown type name 'GDALRIOResampleAlg'; did you mean 'GDALResampleAlg'?
    SWIGINTERN CPLErr GDALDatasetShadow_ReadRaster1(GDALDatasetShadow *self,int xoff,int yoff,int xsize,int ysize,void **buf,int *buf_xsize=0,int *buf_ysize=0,GDALDataType *buf_type=0,int band_list=0,int *pband_list=0,GIntBig *buf_pixel_space=0,GIntBig *buf_line_space=0,GIntBig *buf_band_space=0,GDALRIOResampleAlg resample_alg=GRIORA_NearestNeighbour,GDALProgressFunc callback=NULL,void *callback_data=NULL){
                                                                                                                                                                                                                                                                                                         ^~~~~~~~~~~~~~~~~~
                                                                                                                                                                                                                                                                                                         GDALResampleAlg
    /usr/local/Cellar/gdal/1.11.3_1/include/gdalwarper.h:56:3: note: 'GDALResampleAlg' declared here
    } GDALResampleAlg;
      ^
    extensions/gdal_wrap.cpp:4361:326: error: use of undeclared identifier 'GRIORA_NearestNeighbour'; did you mean 'GRA_NearestNeighbour'?
    SWIGINTERN CPLErr GDALDatasetShadow_ReadRaster1(GDALDatasetShadow *self,int xoff,int yoff,int xsize,int ysize,void **buf,int *buf_xsize=0,int *buf_ysize=0,GDALDataType *buf_type=0,int band_list=0,int *pband_list=0,GIntBig *buf_pixel_space=0,GIntBig *buf_line_space=0,GIntBig *buf_band_space=0,GDALRIOResampleAlg resample_alg=GRIORA_NearestNeighbour,GDALProgressFunc callback=NULL,void *callback_data=NULL){
                                                                                                                                                                                                                                                                                                                                         ^~~~~~~~~~~~~~~~~~~~~~~
                                                                                                                                                                                                                                                                                                                                         GRA_NearestNeighbour
    /usr/local/Cellar/gdal/1.11.3_1/include/gdalwarper.h:49:56: note: 'GRA_NearestNeighbour' declared here
      /*! Nearest neighbour (select on one input pixel) */ GRA_NearestNeighbour=0,
                                                           ^
    extensions/gdal_wrap.cpp:4425:5: error: unknown type name 'GDALRasterIOExtraArg'
        GDALRasterIOExtraArg sExtraArg;
        ^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    4 warnings and 20 errors generated.
    error: command '/usr/bin/clang' failed with exit status 1

    ----------------------------------------
Command "/Users/omrivolk/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/2x/sp5ytf0n11zf01vr0s11_mph0000gn/T/pip-build-slMMiq/GDAL/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/2x/sp5ytf0n11zf01vr0s11_mph0000gn/T/pip-02Yxar-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/2x/sp5ytf0n11zf01vr0s11_mph0000gn/T/pip-build-slMMiq/GDAL

Googled for a few hours but couldn't solve it.

Best Answer

Use Anaconda: https://www.anaconda.com

Open up Terminal: conda install gdal