[Fixed]-Django: Could not find the GDAL library (OSX)

14👍

Okay figured it out thanks to this post, the pertinent info for me was:

The solution is to manually set GDAL_LIBRARY_PATH (link) and
GEOS_LIBRARY_PATH (link) in settings.py:

GDAL_LIBRARY_PATH = '/opt/homebrew/opt/gdal/lib/libgdal.dylib'
GEOS_LIBRARY_PATH = '/opt/homebrew/opt/geos/lib/libgeos_c.dylib'

3👍

You need to do:

brew install postgis

After that manually set GDAL_LIBRARY_PATH and GEOS_LIBRARY_PATH in settings.py:

GDAL_LIBRARY_PATH = '/opt/homebrew/opt/gdal/lib/libgdal.dylib'
GEOS_LIBRARY_PATH = '/opt/homebrew/opt/geos/lib/libgeos_c.dylib'
👤PSN

0👍

Postgres.app is an application that provides a self-contained PostgreSQL database server for macOS.

The location of GDAL and GEOS library path can vary depending on the version but follows a path like /Applications/Postgres.app/Contents/Versions/xxx/lib. There xxx is version of postgres.app like 14, 15 accordingly.

You need to set the path manually in settings.py like:

GDAL_LIBRARY_PATH = '/Applications/Postgres.app/Contents/Versions/xxx/lib/libgdal.dylib'
GEOS_LIBRARY_PATH = '/Applications/Postgres.app/Contents/Versions/xxx/lib/libgeos_c.dylib'

Replace your version number instead of xxx for question’s author it would be 14.


Better alternate

MacOS tries to locate GDAL library in standard library paths like /usr/local/lib, /usr/lib and locations in DYLD_LIBRARY_PATH environment variable so if you do not prefer adding extra code in settings.py you could add following to your .bashrc or .zshrc

export DYLD_LIBRARY_PATH=/Applications/Postgres.app/Contents/Versions/xxx/lib/

Leave a comment