1. 参考
https://docs.djangoproject.com/en/5.0/ref/contrib/gis/install/#macos
2. 问题描述
苹果系统 Mac 中搭建 GeoDjango 开发环境时出现以下报错:
File "*.venv/lib/python3.8/site-packages/django/contrib/gis/gdal/libgdal.py", line 60, in <module>
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal3.4.0", "gdal3.3.0", "gdal3.2.0", "gdal3.1.0", "gdal3.0.0", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
3. 解决步骤
3.1. 安装依赖包
sudo port install postgresql13-server
sudo port install geos
sudo port install proj6
sudo port install postgis3
sudo port install gdal
sudo port install libgeoip
pip install GDAL=="$(gdal-config --version).*"
3.2. 配置 GDAL_LIBRARY_PATH
sudo find / -name "libgdal*"
找到 libgdal.dylib 的路径
/opt/local/lib/libgdal.dylib
settings.py 中添加以下代码:
GDAL_LIBRARY_PATH = '/opt/local/lib/libgdal.dylib'
3.3. 配置 GEOS_LIBRARY_PATH
sudo find / -name "libgeos_c*"
找到 libgeos_c.dylib 的路径文章来源:https://www.toymoban.com/news/detail-810665.html
/opt/local/lib/libgeos_c.dylib
settings.py 中添加以下代码:文章来源地址https://www.toymoban.com/news/detail-810665.html
GEOS_LIBRARY_PATH = '/opt/local/lib/libgeos_c.dylib'
到了这里,关于Mac Could not find the GDAL library 问题解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!