Skip to content

Instantly share code, notes, and snippets.

@bentaber
Forked from kelvinn/InstallPythonGDAL.md
Last active June 16, 2021 15:34
Show Gist options
  • Save bentaber/eb3252f151a33df0f598c6aae5635415 to your computer and use it in GitHub Desktop.
Save bentaber/eb3252f151a33df0f598c6aae5635415 to your computer and use it in GitHub Desktop.
Installing GDAL (Python 3.7) on Mac OS X

Install GDAL with netcdf support and GDAL Python Bindings via homebrew

Clean up any existing installs with

brew uninstall gdal netcdf libgeotiff libspatialite proj

Add osgeo tap and install (note this will also install python 3.7.7 as a dep)

brew tap osgeo/osgeo4mac && brew tap --repair
brew install osgeo/gdal
brew install ogseo/gdal-python

Test with

gdalinfo --version
gdal_polygonize.py

If both work, you are done. If gdal_polygonize.py doesn't work, follow below:

Make sure this is the same version brew just installed... 3.1.0_2 as of current

ls /usr/local/Cellar/osgeo-gdal/ if you need to get the revision number.

pip download GDAL==3.1.0
tar -xpzf GDAL-3.1.0.tar.gz
cd GDAL-3.1.0
python setup.py build_ext --gdal-config /usr/local/Cellar/osgeo-gdal/3.1.0_2/bin/gdal-config
python setup.py build
python setup.py install

Check

> gdal_polygonize.py
@liamtoney
Copy link

Error: No available formula with the name "osgeo/gdal"

I had to use (the very verbose!) brew install osgeo/osgeo4mac/osgeo-gdal and brew install osgeo/osgeo4mac/osgeo-gdal-python

Otherwise, works for me! 👍

@liamtoney
Copy link

I had to use (the very verbose!) brew install osgeo/osgeo4mac/osgeo-gdal and brew install osgeo/osgeo4mac/osgeo-gdal-python

Looks like brew install osgeo-gdal and brew install osgeo-gdal-python also work as shortcuts once the tap is tapped

@bentaber
Copy link
Author

Updated above for GDAL 3.1.0. If you are upgrading, run brew upgrade osgeo-gdal and then follow the subsequent steps above for python bindings.

@tjwebb
Copy link

tjwebb commented Sep 3, 2020

well, import osgeo doesn't work, but import gdal does. Is this expected? I've been too busy cursing the gdal people and forgot to write down all the commands I ran to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment