Django.core.exceptions.ImproperlyConfigured:找不到 GDAL 库,是否安装了 GDAL?

问题描述 投票:0回答:0

这来自我在这里的问题的延续:

GDAL设置命令错误:use_2to3无效

由于错误的性质已经改变,所以单独发布很重要。 我在 GCPUbuntu 18.04 LTS 上使用 django 3.2 运行 Django rest api。我在运行 docker-compose 命令时遇到问题。踪迹指向 Gdal

由于 setuptools==67.6.0 和 gdal==2.4.2 之间的冲突并导致链接问题中的先前错误(未解决),我尝试了以下操作:

我删除了 requirements.txt 中的 gdal 包并使用了以下内容:

sudo apt install libgdal-dev
pip3 install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')

上面显示使用旧版 setup.py,它识别 gdal-config 版本为 2.4(而不是 2.4.2)并安装它。

现在,当我运行 docker-compose 和容器时,我得到以下信息:

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal3.1.0", "gdal3.0.0", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

其他软件包的设置工具保持在 67.6.0,而 gdal 是使用旧版安装程序单独安装的(不是来自 requirements.txt)。

我已经试过了:

sudo apt install libgdal-dev --upgrade
sudo apt-get install gdal-bin --upgrade

这是针对面临类似问题的用户提到的解决方案。

编辑: 根据@phd 的推荐, 参考帖子后将 GDAL_LIBRARY_PATH 添加到我的 settings.py 中: https://github.com/moose46/Jobbee/blob/master/backend/backend/settings.py#L156 https://docs.djangoproject.com/en/4.1/ref/contrib/gis/install/geolibs/#gdal-library-path

建议的解决方案:

VIRTUAL_ENV_BASE = os.environ.get("ENVIRONMENT")
GDAL_LIBRARY_PATH = VIRTUAL_ENV_BASE + "/home/earthling/myEnv/lib/python3.8/site-packages/osgeo/gdal304.dll"

然而, 以下是osgeo文件夹里面的,gdal304.dll是没有的

运行 docker-compose 后现在得到以下跟踪:

OSError: development/home/earthling/myEnv/lib/python3.8/site-packages/osgeo/gdal304.dll: cannot open shared object file: No such file or directory
python-3.x ubuntu-18.04 gdal
© www.soinside.com 2019 - 2024. All rights reserved.