Intel Macでは簡単だったがM1 Macで詰まった
1. Homebrewでgdalをインストール(arm64アーキテクチャ)
$ brew install gdal
自分の場合は /opt/homebrew/Cellar/gdal/3.5.0/ にインストールされた。
アーキテクチャを調べるとarm64であることが確認できた。
$ file /opt/homebrew/Cellar/gdal/3.5.0/lib/libgdal.dylib /opt/homebrew/Cellar/gdal/3.5.0/lib/libgdal.dylib: Mach-O 64-bit dynamically linked shared library arm64
2. Python pipでgdalをインストール。pythonはarm64アーキテクチャである必要がある。
自分の場合はpythonコマンドがpyenvでインストールしたpython3.9.2(Universal)、python3コマンドがhomebrewでインストールしたpython3.9.13(arm64)に割り当てられていた。
$ file $(which python3) /opt/homebrew/bin/python3: Mach-O 64-bit executable arm64
pipでgdalをインストール
$ python3 -m pip install gdal
動作確認
$ python3 Python 3.9.13 (main, May 24 2022, 21:13:51) [Clang 13.1.6 (clang-1316.0.21.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from osgeo import gdal >>>