pythondjangohomebrewgdal

Loading of GDAL library impossible after an upgrade


I have a Python environment with Django 3 that has to use GDAL (because the DB engine I use is django.contrib.gis.db.backends.postgis). After an upgrade of GDAL (from 3.6.4_6 to 3.7.1_1), I have this exception on any command to run the django project :

  File "~/.pyenv/versions/3.8.9/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/lib/libgdal.dylib, 0x0006): Symbol not found: __ZN3Aws6Client19ClientConfigurationC1Ev
  Referenced from: <FA8C3295-2793-3C69-A419-16C41753696B> /opt/homebrew/Cellar/apache-arrow/12.0.1_4/lib/libarrow.1200.1.0.dylib
  Expected in:     <BDB1F1E3-0BE9-3D7D-A57E-9D9F8CAD197A> /opt/homebrew/Cellar/aws-sdk-cpp/1.11.145/lib/libaws-cpp-sdk-core.dylib

I've managed to isolate the problem in a fresh python environment with only loading the GDAL library : from ctypes import CDLL; CDLL("/usr/local/lib/libgdal.dylib").

Note, I'm on a Mac (CPU M2 Pro), I've installed GDAL and all its dependancies via brew. I've tried reinstalling it from fresh but it didn't change a thing and I've also tried with different python versions.

Aftermatch: An issue was opened soon after my post (#140082) and the pull request (!140127) fixing it was merged on the 22nd of August 2023. So you just need to do brew update && brew upgrade


Solution

  • I faced the same OSError: dlopen(/usr/local/lib/libgdal.dylib, 0x0006): Symbol not found: __ZN3Aws6Client19ClientConfigurationC1Ev . Applied the approach suggested by @bennylope (https://nelson.cloud/how-to-install-older-versions-of-homebrew-packages/) and got it worked:

    wget https://raw.githubusercontent.com/Homebrew/homebrew-core/824c551b4f514e7cd86358133924906b982c87e2/Formula/postgis.rb 
    wget https://raw.githubusercontent.com/Homebrew/homebrew-core/0faa586d8415cd2ced33345aa3e13c664c92aeda/Formula/a/aws-sdk-cpp.rb
    brew install postgis.rb
    brew uninstall --ignore-dependencies aws-sdk-cpp
    brew install aws-sdk-cpp.rb
    brew link aws-sdk-cpp