1 | initial version |
To configure GDAL for Django on a Mac, follow these steps:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
install gdal
import os
GDAL_LIBRARY_PATH = os.environ.get('GDAL_LIBRARY_PATH')
if GDAL_LIBRARY_PATH is not None:
try:
# Add GDAL library path to the system path
os.environ['PATH'] = GDAL_LIBRARY_PATH + ':' + os.environ['PATH']
# Add GDAL library path to the library search path
os.environ['DYLD_LIBRARY_PATH'] = GDAL_LIBRARY_PATH + ':' + os.environ['DYLD_LIBRARY_PATH']
# Add GDAL library path to the loader search path
os.environ['LD_LIBRARY_PATH'] = GDAL_LIBRARY_PATH + ':' + os.environ['LD_LIBRARY_PATH']
# Verify if GDAL library is accessible
from django.contrib.gis import gdal
except:
pass
/usr/local/Cellar/gdal/3.3.0_1/lib
with the path where GDAL library was installed:GDAL_LIBRARY_PATH=/usr/local/Cellar/gdal/3.3.0_1/lib
django.contrib.gis import gdal
If there are no errors, then GDAL is successfully configured for Django on your Mac.