Skip to content

Instantly share code, notes, and snippets.

@codingjoe
Created March 11, 2021 10:29
Show Gist options
  • Save codingjoe/a31405952ec936beba99b059e665491e to your computer and use it in GitHub Desktop.
Save codingjoe/a31405952ec936beba99b059e665491e to your computer and use it in GitHub Desktop.
HowTo run GeoDjango and PostGIS on M1 macOS arm64 MacBook
  1. Install PostgreSQL with PostGIS via Postges.app
  2. Install brew as recommended.
  3. Install dependencies:
    brew install geos gdal
    
  4. Add the following to your settings:
    # settings.py
    GDAL_LIBRARY_PATH = os.getenv('GDAL_LIBRARY_PATH')
    GEOS_LIBRARY_PATH = os.getenv('GEOS_LIBRARY_PATH')
    
  5. Run Django with the following command, or set variables in your local enviornmeht:
    GDAL_LIBRARY_PATH=/opt/homebrew/lib/libgdal.dylib GEOS_LIBRARY_PATH=/opt/homebrew/lib/libgeos_c.dylib ./manage.py runserver
    
@imtipu
Copy link

imtipu commented Dec 13, 2022

mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')

I am actually getting this error. Tried brew gdal path and conda gdal.
using M1 Pro mac, Python 3.8

@codingjoe
Copy link
Author

mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')

I am actually getting this error. Tried brew gdal path and conda gdal. using M1 Pro mac, Python 3.8

Hi @imtipu, thanks for reaching out. It looks to me, you are running your terminal via Rosetta in x86_64-mode. You don't need that, and I wouldn't recommend to. You can get everything for arm64 these days via Homebrew. A quick uname -m should show you what architecture you are running.

@meteozond
Copy link

Yet another approach ln -s /opt/homebrew/lib ~/lib

@lsharma-ridecell
Copy link

lsharma-ridecell commented Apr 18, 2023

mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')
I am actually getting this error. Tried brew gdal path and conda gdal. using M1 Pro mac, Python 3.8

Hi @imtipu, thanks for reaching out. It looks to me, you are running your terminal via Rosetta in x86_64-mode. You don't need that, and I wouldn't recommend to. You can get everything for arm64 these days via Homebrew. A quick uname -m should show you what architecture you are running.

what is the solution even I tried arch -x86_64 /usr/local/homebrew/bin/brew install gdal but it failed to install gobject-introspection
error
FAILED: tests/scanner/SLetter-1.0.gir
/private/tmp/gobject-introspection-20230418-13944-1ckcej3/gobject-introspection-1.76.1/build/tools/g-ir-scanner --quiet --output=tests/scanner/SLetter-1.0.gir --no-libtool --reparse-validate --add-include-path /private/tmp/gobject-introspection-20230418-13944-1ckcej3/gobject-introspection-1.76.1/gir --add-include-path /private/tmp/gobject-introspection-20230418-13944-1ckcej3/gobject-introspection-1.76.1/build/gir --warn-all --warn-error --namespace=SLetter --nsversion=1.0 --identifier-prefix=S --include=Gio-2.0 --library=sletter-1.0 --c-include=sletter.h -L /private/tmp/gobject-introspection-20230418-13944-1ckcej3/gobject-introspection-1.76.1/build/tests/scanner -I /private/tmp/gobject-introspection-20230418-13944-1ckcej3/gobject-introspection-1.76.1/tests/scanner -I /private/tmp/gobject-introspection-20230418-13944-1ckcej3/gobject-introspection-1.76.1/tests/scanner/.. ../tests/scanner/sletter.c ../tests/scanner/sletter.h
Error in sitecustomize; set PYTHONVERBOSE for traceback:
NameError: name 'new_prefix' is not defined
:: Warning: SLetter: (ErrorQuarkFunction)spawn_error_quark: s_spawn_error_quark: return value: Unresolved type: 'GQuark'
:: Warning: SLetter: (ErrorQuarkFunction)dbus_error_quark: s_dbus_error_quark: return value: Unresolved type: 'GQuark'
:: Fatal: SLetter: warnings configured as fatal
:: Fatal: SLetter: warnings configured as fatal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment