【问题标题】:GeoDjango GEOSException errorGeoDjango GEOSException 错误
【发布时间】:2013-09-09 17:46:38
【问题描述】:

尝试在我的机器上安装 GeoDjango。我对 Python 非常陌生,并且被带入了一个对其他团队成员来说安装起来非常棘手的项目。我使用 brew 安装了 Python 2.7 和 GEOS,并运行了 PSQL 9.2.4,但是当我尝试让网络服务器运行时不断收到此错误:

__import__(name)
File "/Users/armynante/Desktop/uclass-files/uclass-env/lib/python2.7/site
packages/django/contrib/gis/geometry/backend/geos.py", line 1, in <module>
from django.contrib.gis.geos import (
File "/Users/armynante/Desktop/uclass-files/uclass-env/lib/python2.7/site
packages/django/contrib/gis/geos/__init__.py", line 6, in <module>
from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex
File "/Users/armynante/Desktop/uclass-files/uclass-env/lib/python2.7/site
packages/django/contrib/gis/geos/geometry.py", line 14, in <module>
from django.contrib.gis.geos.coordseq import GEOSCoordSeq
File "/Users/armynante/Desktop/uclass-files/uclass-env/lib/python2.7/site-
packages/django/contrib/gis/geos/coordseq.py", line 9, in <module>
from django.contrib.gis.geos.libgeos import CS_PTR
File "/Users/armynante/Desktop/uclass-files/uclass-env/lib/python2.7/site-
packages/django/contrib/gis/geos/libgeos.py", line 119, in <module>
_verinfo = geos_version_info()
File "/Users/armynante/Desktop/uclass-files/uclass-env/lib/python2.7/site
packages/django/contrib/gis/geos/libgeos.py", line 115, in geos_version_info
if not m: raise GEOSException('Could not parse version info string "%s"' % ver)
django.contrib.gis.geos.error.GEOSException: Could not parse version info string
"3.4.2-CAPI-1.8.2 r3921"

似乎无法在 SO 或网络上找到与此跟踪相关的任何内容。我认为这可能是正则表达式失败?我目前正在尝试重新安装 PSQL 和 GEOS 以查看是否可以使其运行。

这是我的需求文件:

django==1.4
psycopg2==2.4.4
py-bcrypt==0.4
python-memcached==1.48
south==0.7.3

# Debug Tools
sqlparse==0.1.3
django-debug-toolbar==0.9.1
django-devserver==0.3.1

# Deployment
fabric==1.4

# AWS
# boto==2.1.1
django-storages==1.1.4
django-ses==0.4.1

# ECL
http://packages.elmcitylabs.com/ecl_django-0.5.3.tar.gz#ecl_django
http://packages.elmcitylabs.com/ecl_google-0.2.14.tar.gz#ecl_google
# https://packages.elmcitylabs.com/ecl_tools-0.3.7.tar.gz#ecl_tools
# https://packages.elmcitylabs.com/chargemaster-0.2.19.tar.gz
# https://packages.elmcitylabs.com/ecl_facebook-0.3.12.tar.gz#ecl_facebook
# https://packages.elmcitylabs.com/ecl_twitter-0.3.3.tar.gz#ecl_twitter

# Search
#https://github.com/elmcitylabs/django-haystack/tarball/issue-522#django-haystack
-e git+https://github.com/toastdriven/django-haystack.git#egg=django-haystack

pysolr==2.1.0-beta
# whoosh==2.3.2

# Misc
# PIL
# django-shorturls==1.0.1
# suds==0.4

django-mptt
sorl-thumbnail

stripe
pytz==2013b

【问题讨论】:

  • 可能是您使用的版本的问题。尝试将其更新到更高版本。更多here
  • 是的,我以前看过那张票。我目前正在重新安装它,如果不起作用,我会尝试升级到下一个版本。
  • 我在我的 Mac 上遇到了同样的问题。不知道是什么原因造成的。如果你解决了,请发布解决方案。

标签: python django homebrew geodjango


【解决方案1】:

这是我的解决方案(显然它很难看,就像我的英语一样,但有效)。 问题是版本字符串在正则表达式中有一个不需要的空格。

错误提示:

GEOSException:无法解析版本信息字符串“3.4.2-CAPI-1.8.2 r3921”

geos_version_info 警告:

正则表达式应该可以解析版本字符串如 '3.0.0rc4-CAPI-1.3.3'、'3.0.0-CAPI-1.4.1' 或 '3.4.0dev-CAPI-1.8.0'

编辑此文件: site-packages/django/contrib/gis/geos/libgeos.py

查找函数: geos_version_info

并更改此行:

ver = geos_version().decode()

用这一行:

ver = geos_version().decode().split(' ')[0]

还有另一个问题,最后有一个空格,但没有提供更多信息。此类版本也与版本正则表达式不匹配,因此 strip()-ping 版本可能是预期的快速修复行为。在我的例子中是:'3.8.0-CAPI-1.13.1 '

【讨论】:

  • 我用 1.9 GDAL Kyung Khaos 包和 PSQL1.9 重新安装了 GEOS,错误消失了,所以很遗憾我无法对此进行测试。它对你有用吗,还是这只是一个建议?
  • 这对我有用,在 ArchLinux 更新后我的 django 代码被破坏了。
  • 本站使用的版本是ver = geos_version(),谢谢!
  • 你是救命稻草
  • 我遇到了给定的错误,我只将我的 python 从两个升级到三个,因为我的代码是用 python3 编写的。我的问题解决了。
【解决方案2】:

在最新的 GEOS 安装中,上述答案不起作用...但接近问题。

我更改了 geos_version_info() 正上方的正则表达式: 来自:

version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)$')

成为:

version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+).*$')

注意添加到正则表达式末尾的 .*。

【讨论】:

  • 这对我来说非常有效。但是,标记为已接受的答案在我的设置中失败。
  • 这对我有用(谢谢!),但接受的答案也对我有用,并且应用起来可能更简单一些。
【解决方案3】:

我认为这又被打破了。我们的 FreeBSD 服务器最近的一次升级导致了这个错误:

django.contrib.gis.geos.error.GEOSException: Could not parse version info string "3.6.2-CAPI-1.10.2 4d2925d6"

看起来 Django 的 libgeos.py 中的正则表达式需要再次更新以适应这种不同的语法。 Nachopro 的解决方案仍然可以作为一种解决方法。

【讨论】:

  • 看起来在 Django v1.11.5 中有一个commit 来修复它
  • 感谢更新,刚刚在 OS X (10.11) 上发现了同样的问题。
  • 是的,在 Django 1.11.4、Python 3.6 和 macOS Sierra 中损坏。
  • 对于 MacOS 上通过 Homebrew 安装的用户,我使用以下方法安装了旧版本 brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/d8764c105feb474b47fe291815112ae1d0fb91ef/Formula/postgis.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/d8764c105feb474b47fe291815112ae1d0fb91ef/Formula/geos.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/d8764c105feb474b47fe291815112ae1d0fb91ef/Formula/gdal.rb
  • FWIW 我所做的是运行brew switch geos 3.6.1,因为我的 Homebrew 在将其升级到 3.6.2 时保持 3.6.1 左右(这是 Homebrew 中的默认行为,除非您运行 brew cleanup)。跨度>
【解决方案4】:

对于那些以前没有安装 3.6.1 的人:

  1. brew unlink geos
  2. 使用brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/145b22e8330e094ee148861e72e26c03e73d34a1/Formula/geos.rb 安装 3.6.1。
  3. brew info geos 应该显示 3.6.1 星标:

【讨论】:

    【解决方案5】:

    截至去年 3 月左右,Django 中的 this has been fixed 似乎。另见Django bug 20036。所以升级到 Django 1.5.4 就可以解决这个问题。

    【讨论】:

    • 我承认我的原始帖子是基于几个推论,但现在看,这不表明修复是在 1.4.8 中吗? github.com/django/django/blob/1.4.8/django/contrib/gis/geos/…
    • 不,那里的正则表达式不会匹配有问题的版本号。恐怕修复只在 1.5 中。
    • 如上面@Kirkman14 的回答中所述,这是坏的;具有讽刺意味的是,我正在尝试安装的项目是 Django 1.5.4,但我在四年前明天找到的修复程序并不是针对较新版本的 libgeos 的修复程序。美好时光!
    【解决方案6】:

    Brew 刚刚发布了 geos 3.8.0,它当然再次打破了 Django 1.11。 之前的版本 3.7.3 被现在在升级时运行的全新的全自动清理功能清除了非常有帮助,所以我没有brew switch geos 3.7.3

    我最终使用this post 来了解如何找到以前的版本号和提交哈希:

    cd $( brew --prefix )/Homebrew/Library/Taps/homebrew/homebrew-core
    git log -- Formula/geos.rb | less
    # find the version you need in the file, copy its hash
    brew unlink geos
    brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/<yourcommithash>/Formula/geos.rb
    

    毕竟,geos 3.7.3 的下载由于某种原因未能通过 SHA256 校验和验证......所以我最终尝试了 3.7.2,它确实有效。

    目前在 Catalina 上重新安装 3.7.2 的命令是:

    brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/823b700ab61eeec57f34d50be2cc34a285fb5abc/Formula/geos.rb
    

    【讨论】:

      【解决方案7】:

      如果有人因任何原因无法自行编辑站点包,那么这个丑陋的 hack 为我完成了它,而无需对环境本身采取行动:

      try:
          __import__('django.contrib.gis.geos.libgeos', fromlist=['version_regex'])
      except Exception as e:
          import re
          att = __import__('django.contrib.gis.geos.libgeos', fromlist=['version_regex'])
          setattr(att, 'version_regex', re.compile(
            '^(?P<version>(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<subminor>\\d+))((rc(?P<release_candidate>\\d+))|dev)?-CAPI-(?P<capi_version>\\d+\\.\\d+\\.\\d+)( r\\d+)?( \\w+)?.*$'))
          assert str(type(e)) == "<class 'django.contrib.gis.geos.error.GEOSException'>", str(e)
      

      它基于JayCrossler's answer

      更新

      上面执行了在django.contrib.gis.geos.__init__.py 模块中找到的代码,该模块已经尝试使用有问题的部分,导致上面的解决方案无法使用(对于python 2.7+)。这可以解决为:

      import sys
      try:
          import django.contrib.gis.geos.libgeos
      except Exception as e:
          import re
          setattr(sys.modules['django.contrib.gis.geos.libgeos'],'version_regex', re.compile(
              '^(?P<version>(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<subminor>\\d+))((rc(?P<release_candidate>\\d+))|dev)?-CAPI-(?P<capi_version>\\d+\\.\\d+\\.\\d+)( r\\d+)?( \\w+)?.*$'))
          assert str(type(e)) == "<class 'django.contrib.gis.geos.error.GEOSException'>", str(e)
      

      基本上我们是直接作用于sys.modules 中的模块,而不是尝试从另一个会失败的导入中获取它。

      【讨论】:

        【解决方案8】:

        这可以通过尝试以下方法来解决,

        brew switch geos 3.6.1

        【讨论】:

        【解决方案9】:

        我通过使用 https://postgresapp.com/downloads.html 安装带有 Postgres 的 PostGIS 解决了这个问题。

        1. 安装 PostGIS (2.2):brew install postgis
        2. 如果版本高于 3.6.1,要取消链接 geos:brew unlink geos
        3. 安装 Geos (3.6.1): brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/145b22e8330e094ee148861e72e26c03e73d34a1/Formula/geos.rb
        4. 切换 geos 版本(最新版本是 3.7.2,Django 1.11.3 不支持):brew switch geos 3.6.1
        5. 登录数据库并创建 postgis 扩展:CREATE EXTENSION postgis; 测试 postgis 扩展:SELECT ST_Distance('LINESTRING(-122.33 47.606, 0.0 51.5)'::geography, 'POINT(-21.96 64.15)'::geography);
        6. 检查 postgis 版本:SELECT PostGIS_full_version();

        【讨论】:

          猜你喜欢
          • 2015-01-16
          • 1970-01-01
          • 1970-01-01
          • 2018-11-03
          • 2015-06-05
          • 2021-01-07
          • 2014-10-08
          • 2011-04-03
          • 2012-02-24
          相关资源
          最近更新 更多