[GIS] using GDAL installed using homebrew from python on OSX

gdalhomebrewjpeg 2000osxpython

I would like to work with jpeg2000 files in python but when I install GDAL using pip or conda it can't read jpeg2000s.

GDAL's version is: 2.1.0
module 'osgeo.gdal' from '/Applications/anaconda/lib/python3.5/site-packages/osgeo/gdal.py'

I found this guide to installing gdal 2 on osx which I followed and I now have a version of gdal installed which can deal with jpeg2000.

user$ gdalinfo --formats | grep -i jp
  JPEG -raster- (rwv): JPEG JFIF
  JP2OpenJPEG -raster,vector- (rwv): JPEG-2000 driver based on OpenJPEG library
  JPEG2000 -raster,vector- (rwv): JPEG-2000 part 1 (ISO/IEC 15444-1), based on Jasper library

My question is how can I make python use this version of GDAL and not the one that is downloaded by pip or conda with the gdal package?

Best Answer

If you are already working with conda a better option would be to install GDAL 2.1 though conda rather than trying to install via homebrew and use this version with conda (which is likely to cause conflicts between different versions of packages). The conda-forge community packages have a version of GDAL 2.1 built with support for JPEG2000 via the OpenJPEG library. You can install using:

conda create -n gdal2 -c conda-forge gdal -y
source activate gdal2

Running your grep command should give:

gdalinfo --formats | grep -i jp
  JPEG -raster- (rwv): JPEG JFIF
  JP2OpenJPEG -raster,vector- (rwv): JPEG-2000 driver based on OpenJPEG library