Skip to content

Instantly share code, notes, and snippets.

@whalesalad
Created August 23, 2016 18:13
Show Gist options
  • Save whalesalad/e5143432f6b69dba3303d07ccb8d8d39 to your computer and use it in GitHub Desktop.
Save whalesalad/e5143432f6b69dba3303d07ccb8d8d39 to your computer and use it in GitHub Desktop.

GDAL on OS X

This will resolve issues with GDAL on OS X in your virtualenv:

  • brew install gdal
  • From OUTSIDE a virtualenv (try, deactivate), run this command to find your system site-packages directory: python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
    • Chances are this will be /Library/Python/2.7/site-packages
    • Note: this is where pip install ... packages are placed
  • Copy the gdal-XXX.pth file to the site-packages directory of your virtual environment.
  • Find your site packages directory for your virtual env by running the earlier command, python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())", from inside an activated virtualenv.

Example, I use ~/Envs as my WORKON_HOME (where virtualenv creates environments), so my command would be:

cp /Library/Python/2.7/site-packages/gdal-py2.7.pth ~/Envs/rex/lib/python2.7/site-packages/gdal.pth

Now GDAL will work inside Python.

In production deployments this dependency is handled entirely inside of the Dockerfile.

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