Ask Your Question
1

How to configure GDAL for Django on a Mac with regards to the exception of GDAL_LIBRARY_PATH?

asked 2023-04-28 22:44:50 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-04-28 22:53:01 +0000

ladyg gravatar image

To configure GDAL for Django on a Mac, follow these steps:

  1. Install Homebrew package manager if you haven't already. Open Terminal.app and execute the following command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. Install GDAL library using Homebrew by running the following command in Terminal:

install gdal

  1. Configure GDAL path in Django settings.py file. Open Terminal and navigate to your Django project folder. Open settings.py file and add the following code:
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
  1. Export GDALLIBRARYPATH environment variable by running the following command in Terminal, replacing /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

  1. Restart your Django server and verify that GDAL library is accessible by running the following command in Python shell:

django.contrib.gis import gdal

If there are no errors, then GDAL is successfully configured for Django on your Mac.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-04-28 22:44:50 +0000

Seen: 13 times

Last updated: Apr 28 '23