如何修复 'django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library'

how to fix the 'django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library'

我正在尝试将商店的位置存储在我的 django 数据库中,我尝试安装 geodjango 的目的是出现上述错误。

我已经安装了 python postgresql 奥斯乔 心理战警2 还根据 geodjango 文档修改了环境变量

我尝试使用 -http://www.gisinternals.com/query.html?content=filelist&file=release-1911-x64-gdal-2-2-3-mapserver-7-0-7.zip 手动安装 gdal 通用核心组件

我的settings.py文件-

import os
if os.name == 'nt':
    import platform
    OSGEO4W = r"C:\OSGeo4W"
    if '64' in platform.architecture()[0]:
        OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
    os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
    os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']


INSTALLED_APPS = [
...
'django.contrib.gis',
]

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'services',
        'USER': '*******',
        'HOST': 'localhost',
        'PASSWORD': '******',
        'PORT': '5434',
    }

当我运行

python manage.py check

它给我错误

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal202", "gdal201", "gdal20", "gdal111", "gdal110", "gdal19"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

我已经将 gdal 库路径设置为 gdal 数据目录,它仍然无法正常工作。

以上有什么问题请帮忙解决。

另外建议是否有任何其他方法可以在 django 数据库中存储位置?

在 GDAL 库中也添加 gdal300。当你现在安装 GDAL 时,你会得到 gdal300OSGeo4w64/bin 目录中。 接下来,你可能会得到一个错误:django.core.exceptions.ImproperlyConfigured: jsonfield dependency missing

有一个简单的修复方法。 pip install jsonfield

这应该有效。 如果这不起作用

运行 在您的命令提示符中将其作为 bat 脚本。

set OSGEO4W_ROOT=C:\OSGeo4W
set PYTHON_ROOT=C:\Python3X
set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal
set PROJ_LIB=%OSGEO4W_ROOT%\share\proj
set PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%\bin
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session 
Manager\Environment" /v Path /t REG_EXPAND_SZ /f /d "%PATH%"
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session 
Manager\Environment" /v GDAL_DATA /t REG_EXPAND_SZ /f /d "%GDAL_DATA%"
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session 
Manager\Environment" /v PROJ_LIB /t REG_EXPAND_SZ /f /d "%PROJ_LIB%"

注意:您需要在 c 盘中重命名 c:/OSGEO4w64' toc:/OSGEO4w` 才能使用上面显示的脚本。

在此处查找详细信息: https://docs.djangoproject.com/en/3.0/ref/contrib/gis/install/

我 运行 这个对我有用。

set OSGEO4W_ROOT=C:\OSGeo4W
set PYTHON_ROOT=C:\Python3X
set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal
set PROJ_LIB=%OSGEO4W_ROOT%\share\proj

我只是切换到 linux 它 worked.Although 问题出在某处有一个库 windows 无法弄清楚,切换到 linux 解决了问题。