【问题标题】:Django / Ubuntu 20 - How change to a previous version of GDALDjango / Ubuntu 20 - 如何更改为先前版本的 GDAL
【发布时间】:2020-10-05 20:12:35
【问题描述】:

首先,感谢您的帮助。

我是 django 的新手,我正在开发一个网站,您必须在其中输入某些形式的坐标,然后它们应该是可编辑的。

到目前为止,一切都很好,我在创建它时没有任何问题,但是,正如我所读到的,在一些较新的版本中,GDAL 读取坐标的顺序发生了变化,因此当位置出现倒置时从地理空间数据库中读取数据。换句话说,坐标是正确输入的(从 PgAdmin 来看,它们看起来是正确的)但是当您使用 Django 将它们加载到传单地图中时会读取错误。

我询问了如何解决这个问题 (Link to my previous question),但没有得到答案,也无法自己解决。因此,我唯一能想到的就是尝试使用以前版本的 GDAL,但是,我不太确定该怎么做。我按照以下步骤安装它:

pip3 install gdal
sudo apt-get install gdal-bin libgdal-dev
sudo apt-get install python3-gdal

提前致谢

编辑:

我尝试使用 2.x.x 版本,但我在 3 以下的每个版本中都遇到了一些错误。

执行pip3 install gdal==2.4.4 时,首先我得到错误command 'x86_64-linux-gnu-gcc' failed with status 1ERROR: Failed building wheel for gdal。然后它成功卸载 GDAL 3.0.4 并在一段时间后报告另一个状态 1:

ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-cjqeh4e7/gdal/setup.py'"'"'; __file__='"'"'/tmp/pip-install-cjqeh4e7/gdal/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_71slwxo/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/ecolab/.local/include/python3.8/gdal Check the logs for full command output.
2020-06-16T11:34:18,929 Exception information:
2020-06-16T11:34:18,929 Traceback (most recent call last):
2020-06-16T11:34:18,929   File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 186, in _main
2020-06-16T11:34:18,929     status = self.run(options, args)
2020-06-16T11:34:18,929   File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 421, in run
2020-06-16T11:34:18,929     installed = install_given_reqs(
2020-06-16T11:34:18,929   File "/usr/lib/python3/dist-packages/pip/_internal/req/__init__.py", line 67, in install_given_reqs
2020-06-16T11:34:18,929     requirement.install(
2020-06-16T11:34:18,929   File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 820, in install
2020-06-16T11:34:18,929     install_legacy(
2020-06-16T11:34:18,929   File "/usr/lib/python3/dist-packages/pip/_internal/operations/install/legacy.py", line 70, in install
2020-06-16T11:34:18,929     runner(
2020-06-16T11:34:18,929   File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 271, in runner
2020-06-16T11:34:18,929     call_subprocess(
2020-06-16T11:34:18,929   File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 242, in call_subprocess
2020-06-16T11:34:18,929     raise InstallationError(exc_msg)
2020-06-16T11:34:18,929 pip._internal.exceptions.InstallationError: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-cjqeh4e7/gdal/setup.py'"'"'; __file__='"'"'/tmp/pip-install-cjqeh4e7/gdal/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_71slwxo/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/ecolab/.local/include/python3.8/gdal Check the logs for full command output.

【问题讨论】:

    标签: python django ubuntu version gdal


    【解决方案1】:

    不幸的是,ubuntugis PPA https://launchpad.net/~ubuntugis/+archive/ubuntu/ppa 中(目前)没有用于焦点 (20.04) 的 GDAL 包。

    最好的方法可能是从源代码构建 GDAL 2.2.4 和 GEOS 3.8.0 库,如下所述:https://docs.djangoproject.com/en/2.2/ref/contrib/gis/install/geolibs/#building-from-source

    如果您的操作系统中已经使用sudo apt-get remove gdal-bin gdal-data libgdal26 安装了GDAL v3 版本,您必须卸载它

    然后您可以执行以下操作:

    安装 GEOS:

    cd /tmp/
    wget https://download.osgeo.org/geos/geos-3.8.0.tar.bz2
    tar xjf geos-3.8.0.tar.bz2
    cd geos-3.8.0
    ./configure
    make
    sudo make install
    

    安装 GDAL:

    cd /tmp/
    wget https://download.osgeo.org/gdal/2.2.4/gdal-2.2.4.tar.gz
    tar xjf gdal-2.2.4.tar.gz
    cd gdal-2.2.4
    ./configure
    make
    sudo make install
    

    运行 ldconfig:

    sudo ldconfig
    

    【讨论】:

    • 我最终决定使用 Leaflet 来生成地图,以及我需要收集地理空间信息的表格。无论如何,我尝试了本杰明提出的解决方案,似乎效果很好。感谢您的宝贵时间,如果 GDAL +3 的问题仍然存在,它可能对未来的项目有用。
    【解决方案2】:

    您是否尝试过使用 pip 安装旧版本?像pip3 install gdal==2.3.3 这样的东西?

    【讨论】:

    • 在 3.0.1 之前的每个版本(我有 3.0.4)中执行此命令时,我在构建轮子时遇到错误。此版本仍然存在此问题。我不确定是什么导致了这些错误。
    • 如果我安装旧版本,告诉 Django 使用旧版本,我是否只需要使用 GDAL_LIBRARY_PATH 指定它还是 django 会自动识别它?
    • 您尝试安装哪个版本?你能添加你得到的确切错误吗?
    • 我用我遇到的错误更新了我的问题,谢谢
    • 我尝试在干净的 ubuntu 20.4 lts 版本上安装 GDAL。看来您要使用 pip 安装的 gdal 版本必须与 apt-get 命令安装的 gdal-bin 版本相同。文档中提到了类似的内容。 mothergeo-py.readthedocs.io/en/latest/development/how-to/…。我尝试使用apt-cache policy 安装/查找旧版本的 gdal-bin,但没有找到。
    猜你喜欢
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    • 1970-01-01
    • 2020-01-27
    • 2017-07-05
    • 2021-12-25
    相关资源
    最近更新 更多