9

I am trying to get GeoDjango running on mac os and have hit a problem with GDAL.

I have downloaded and installed GDAL without problem (Gdal Complete Binary) also installed from homebrew too.

Unfortunately when i was installed gdal with homebrew django can't find the gdal and throws gdal did not find error, after that. I installed from KyngChaos GeoDjango Binary django find gdal but now throws that;

OSError: dlopen(/Library/Frameworks/gdal.framework/gdal, 6): no suitable image found.  Did find:
    /Library/Frameworks/gdal.framework/gdal: mach-o, but wrong architecture
    /Library/Frameworks/gdal.framework/gdal: mach-o, but wrong architecture
    /Library/Frameworks/GDAL.framework/Versions/3.1/GDAL: mach-o, but wrong architecture
    /Library/Frameworks/GDAL.framework/Versions/3.1/GDAL: mach-o, but wrong architecture

I think the Kyngchaos build not compaitable with arm platform

Any help would be much appreciated.

Django Version : 3.0 also tried 3.2
Gdal Version : 3.2/3.1/2.4 All of them tried
Python Version: 3.8
Postgresql Version : 13
Postgis/Geos installed
gdal-config --libs:

-L/opt/homebrew/Cellar/gdal/3.2.2_3/lib -lgdal
Veli Eroglu
  • 147
  • 2
  • 9
  • The wrong architecture seems that you use the intel version. The build from source should be working fine if you use homebrew for native arm64. – rapoma Apr 27 '21 at 13:26
  • Actually Homebrew install arm version successfully but django cannot find the hombrew gdal package, That's why i tried the KyngChaos build. – Veli Eroglu Apr 27 '21 at 13:33
  • That's what happend when I remove KyngChaos builds; django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal3.1.0", "gdal3.0.0", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings. – Veli Eroglu Apr 27 '21 at 13:36
  • 1
    dirty solution, keep the correct architecture arm64 that works and add this to your django settings.py GDAL_LIBRARY_PATH='/opt/homebrew/Cellar/gdal/3.2.2_3/lib/libgdal.dylib' . of course the gdalinfo --version should not give error. This is not for production as I assume you are not gonna use mac m1 for production – rapoma Apr 27 '21 at 13:45
  • Also you need to have the same version of GDAL in your python – rapoma Apr 27 '21 at 13:47
  • ofc is not production, It works thank you so much! (same steps also needed for geos add GEOS_LIBRARY_PATH = '/opt/homebrew/Cellar/geos/3.9.1/lib/libgeos_c.dylib' to settings.py) – Veli Eroglu Apr 27 '21 at 14:59
  • that's great :) – rapoma Apr 27 '21 at 15:02
  • 8
    For anyone who is getting `AttributeError: dlsym(0x102dde9f0, initGEOS_r): symbol not found ` error. After you did everything listed before, make sure that the path in `GEOS_LIBRARY_PATH` ends with `libgeos_c.dylib`, not `libgeos.dylib`. – Leonid Ivanov Aug 04 '21 at 06:47

3 Answers3

2

Find the paths of gdal and geos

find /opt -name "libgdal.dylib" -print 2>/dev/null
find /opt -name "libgeos_c.dylib" -print 2>/dev/null

Copy the output for gdal and geos (might be more than one, pick one of each)

/opt/homebrew/Cellar/gdal/3.6.2/lib/libgdal.dylib
/opt/homebrew/Cellar/geos/3.11.1/lib/libgeos_c.dylib

Put it in the settings.py file

Put it in the DJANGO settings file, the default one is here but your milage may vary:

mysite
 ├── manage.py
 └── mysite
      ├── __init__.py
      └── settings.py

Bottom of the file:

# mysite/mysite/settings.py
GDAL_LIBRARY_PATH="/opt/homebrew/Cellar/gdal/3.6.2/lib/libgdal.dylib"
GEOS_LIBRARY_PATH="/opt/homebrew/Cellar/geos/3.11.1/lib/libgeos_c.dylib"
ViktorMS
  • 1,112
  • 10
  • 25
1

dydl also watches ~/lib folder, so the simplest solution is:

ln -s /opt/homebrew/lib ~/lib

Alexander Klimenko
  • 2,252
  • 1
  • 18
  • 20
-3
brew info gdal

which should give you something like:

/opt/homebrew/Cellar/gdal/3.2.2_3/lib/libgdal.dylib

put that into your GDAL_LIBRARY_PATH.

From here, you can debug it further by putting a break point in your exception's line.

Işık Kaplan
  • 2,815
  • 2
  • 13
  • 28