以下の内容はhttps://seinzumtode.hatenadiary.jp/entry/2024/11/14/210715より取得しました。


GDALのインストール(Intel Mac, M1 Mac)

環境はIntel Mac, macOS 15.1 Sequoia.
brew install gdalでGDAL-3.10がインストールされた。
pip install gdalでgdal-3.10のpipをインストールしようとするとビルドに失敗する。
ソースからのインストールでなんとかできたが、いくつか不可解な点は残った。

ソースからのインストール
mits003.github.io

brew install gdal
pip download GDAL
tar -xpzf GDAL-<version of GDAL>.tar.gz
cd GDAL-<version of GDAL>
python setup.py build_ext --gdal-config /usr/local/Cellar/gdal/<version of GDAL>/bin/gdal-config
python setup.py build
python setup.py install

setup.pyでのエラー

15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/__memory/shared_ptr.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/__memory/unique_ptr.h:170:54: error: member 'nullptr_t' declared as a template
  169 |   template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170 |   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
      |                                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/__memory/unique_ptr.h:170:64: error: expected ';' at end of declaration list
  170 |   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
      |                                                                ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk/usr/include/c++/v1/__memory/unique_ptr.h:238:77: error: unknown type name 'nullptr_t'
  238 |   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
...

C++のSTDライブラリが読み込めていないようなエラーが出る。

terminal - Unable to find include file on newly updated macOS(C/C++) - Ask Different
上記に従ってMacOSX.sdkのシンボリックを削除する

cd /Library/Developer/CommandLineTools/SDKs
rm MacOSX.sdk
python setup.py build
python setup.py install

どうしてもsetup.py installでコケる。

ld: warning: search path '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib' not found
ld: warning: search path '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib' not found
1 warning generated.
1 warning generated.
1 warning generated.
1 warning generated.
1 warning generated.
No eggs found in /var/folders/z1/r5wl186d23314ypyzy3t8wj80000gn/T/easy_install-qnvgu8xo/gdal-3.10/egg-dist-tmp-ypv3k96v (setup script problem?)
error: The 'GDAL==3.10.0' distribution was not found and is required by the application

調べると、.eggファイル自体は所定の場所に展開されている。

ls /Users/shohei/.pyenv/versions/3.9.2/lib/python3.9/site-packages/GDAL-3.10.0-py3.9-macosx-14.2-x86_64.egg
EGG-INFO    osgeo       osgeo_utils

ただしpythonからは読み込めない

$ python
imPython 3.9.2 (default, Oct 10 2021, 07:02:43)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import _gdal
Traceback (most recent call last):
  File "/Users/shohei/Downloads/gdal-3.10/osgeo/__init__.py", line 30, in swig_import_helper
    return importlib.import_module(mname)
  File "/Users/shohei/.pyenv/versions/3.9.2/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'osgeo._gdal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shohei/Downloads/gdal-3.10/osgeo/__init__.py", line 35, in <module>
    _gdal = swig_import_helper()
  File "/Users/shohei/Downloads/gdal-3.10/osgeo/__init__.py", line 32, in swig_import_helper
    return importlib.import_module('_gdal')
  File "/Users/shohei/.pyenv/versions/3.9.2/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_gdal'
>>>

インストールされている場所に移ってそこから呼び出したら、以降どこからでもosgeoを呼び出せるようになった。こういう仕様なのか?

cd /Users/shohei/.pyenv/versions/3.9.2/lib/python3.9/site-packages/GDAL-3.10.0-py3.9-macosx-14.2-x86_64.egg
from osgeo import _gdal


M1 macの場合
こっちはminicondaを使っていたので、condaでインストールできた。

$ which python
/opt/miniconda3/bin/python

$ conda install gdal



以上の内容はhttps://seinzumtode.hatenadiary.jp/entry/2024/11/14/210715より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14