(M1 Mac) Geodjango GDAL: mach-o, but wrong architecture

Question:

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
Asked By: Veli Eroglu

||

Answers:

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.

Answered By: Işık Kaplan

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"
Answered By: ViktorMS

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

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

Answered By: Alexander Klimenko
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.