【问题标题】:Problems with Geodjango and GdalGeodjango 和 Gdal 的问题
【发布时间】:2022-10-18 16:40:05
【问题描述】:

笔记:

使用 Django 4.0.5 和 Python 3.10

IDE:Pycharm 专业版

OSGEO4W 版本:2 (https://download.osgeo.org/osgeo4w/v2/)

问题

我无法让 gis 库在 Django 中工作。我遵循了文档:https://docs.djangoproject.com/en/4.0/ref/contrib/gis/install/#windows。遵循这些步骤后,我收到此错误:

django.core.exceptions.ImproperlyConfigured:找不到 GDAL 库(尝试了“gdal303”、“gdal302”、“gdal301”、“gdal300”、“gdal204”、“gdal203”、“gdal202”、“gdal201”、“gdal20” ")

然后我查看了 OSGEO4W 安装的 GDAL 版本,发现它是 gdal305。所以我进入https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal,在那里我下载了我的python版本(GDAL-3.3.3-cp310-cp310-win_amd64.whl)并使用了命令pip install GDAL-3.3.3-cp310-cp310-win_amd64.whl。然后我更改了路径变量以使用这个版本的 gdal,而不是使用 OSgeo4W 安装的那个。然后我收到以下错误: OSError: [WinError 127] : The specified procedure could not be found

在线阅读后发现stackoverflow如下:OSError in Geodjango: [WinError 127] : The specified procedure could not be found

但是,这对我不起作用,我仍然遇到相同的错误(取决于我设置 gdal 路径的位置)。

我尝试过的其他事情:

  1. 我尝试使用早期版本的 OSgeo4W,但安装程序没有任何可用的下载站点。

  2. 我尝试使用 anaconda 代替 pycharm venv,并通过 conda-forge 下载 gdal、proj、geos。

    如果需要更多信息,请告诉我。第一次写stackoverflow。

【问题讨论】:

  • 此链接可能有用:pointsnorthgis.ca/blog/geodjango-gdal-setup-windows-10 请注意您必须进入 gdal 的环境站点包库并编辑“nt”的 libgdal.py 文件的部分。 Lib\site-packages\django\contrib\gis\gdal\libgdal.py 您可能需要添加“gdal333”,因为它看起来就是您正在使用的版本。
  • 实际上,在我上面的评论中,它应该是“gdal303”,因为如果您查看 lib_names 列表,则以前的版本遵循一种模式。

标签: python django gdal


【解决方案1】:

嗨,在打开它后在 cmd 或终端中运行它(以管理员身份运行):

set OSGEO4W_ROOT=C:OSGeo4W set PYTHON_ROOT=C:Python3X set
 GDAL_DATA=%OSGEO4W_ROOT%sharegdal set
 PROJ_LIB=%OSGEO4W_ROOT%shareproj set
 PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%in reg ADD
 "HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment" /v
 Path /t REG_EXPAND_SZ /f /d "%PATH%" reg ADD
 "HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment" /v
 GDAL_DATA /t REG_EXPAND_SZ /f /d "%GDAL_DATA%" reg ADD
 "HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment" /v
 PROJ_LIB /t REG_EXPAND_SZ /f /d "%PROJ_LIB%" 

然后将其添加到代码中

 settings.py import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


 # use this if setting up on Windows 10 with GDAL installed from OSGeo4W using defaults 
 if os.name == 'nt':
      VIRTUAL_ENV_BASE = os.environ['VIRTUAL_ENV']
      os.environ['PATH'] = os.path.join(VIRTUAL_ENV_BASE, r'.Libsite-packagesosgeo') + ';' + os.environ['PATH']
      os.environ['PROJ_LIB'] = os.path.join(VIRTUAL_ENV_BASE, r'.Libsite-packagesosgeodataproj') + ';' + os.environ['PATH']

【讨论】:

  • 我刚试过这个,它仍然给我错误django.core.exceptions.ImproperlyConfigured:找不到GDAL库(试过“gdal304”,“gdal303”,“gdal302”,“gdal301”,“gdal300”,“gdal204 ”、“gdal203”、“gdal202”)。 GDAL 安装了吗?如果是,请尝试在您的设置中设置 GDAL_LIBRARY_PATH。
猜你喜欢
  • 2019-08-28
  • 1970-01-01
  • 1970-01-01
  • 2017-06-30
  • 2012-02-24
  • 1970-01-01
  • 2020-11-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多