Python GeoDjango GEOSException 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18643998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:18:12  来源:igfitidea点击:

GeoDjango GEOSException error

pythondjangohomebrewgeodjango

提问by armynante

Trying to install a GeoDjango on my machine. I'm really new to Python and being brought into a project that has been a very tricky install for the other team members. I installed Python 2.7 and GEOS using brew, and running PSQL 9.2.4 but keep getting this error when I try to get the webserver running:

试图在我的机器上安装 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"

Cant seem to find anything relevant to this trace on SO or the web. I think it might be a regex failure? I'm currently trying to reinstall PSQL and GEOS to see if I can get it running.

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

Here is my requirements file:

这是我的需求文件:

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

采纳答案by nachopro

This is my solution (obviously it is ugly, like my English, but works). The problem is that the versions string has an white space unwanted in the RegEx.

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

The error says:

错误说:

GEOSException: Could not parse version info string "3.4.2-CAPI-1.8.2 r3921"

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

And the geos_version_info warns:

并且 geos_version_info 警告:

Regular expression should be able to parse version strings such as '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1' or '3.4.0dev-CAPI-1.8.0'

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

Edit this file:site-packages/django/contrib/gis/geos/libgeos.py

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

Look for the function:geos_version_info

寻找函数:geos_version_info

And change this line:

并更改此行:

ver = geos_version().decode()

ver = geos_version().decode()

With this line:

有了这条线:

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

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

There is also another problem, where there is a whitespace at the end but no more information is provided. Such version also doesn't match version regular expression, so strip()-ping the version may be expected behaviour as a quick fix. In my example it was: '3.8.0-CAPI-1.13.1 '

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

回答by Joe Germuska

It appears that this has been fixedin Django as of last March or so. See also Django bug 20036. So upgrading to Django 1.5.4 will solve the problem.

截至去年三月左右,这似乎已在 Django 中修复。另请参阅Django 错误 20036。所以升级到 Django 1.5.4 可以解决这个问题。

回答by JayCrossler

In the latest GEOS install, the above answer didn't work... but was close to the problem.

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

I changed the regex right above the geos_version_info(): from:

我更改了 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+)$')

to be:

成为:

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+).*$')

Notice the .* added to the end of the regex.

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

回答by Kirkman14

I think this is broken again. A recent upgrade on our FreeBSD server led to this error:

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

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

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

Looks like the regex in Django's libgeos.pyneeds to be updated again to account for this different syntax. Nachopro's solution still serves as a workaround.

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

回答by Muneer Muhammed

This can be fixed by trying the following,

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

brew switch geos 3.6.1

酿造开关地理3.6.1

回答by Adam

For those folks who don't have 3.6.1 previously installed:

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

  1. brew unlink geos
  2. Install 3.6.1 with brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/145b22e8330e094ee148861e72e26c03e73d34a1/Formula/geos.rb.
  3. brew info geosshould show 3.6.1 starred: enter image description here
  1. brew unlink geos
  2. 安装 3.6.1 与brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/145b22e8330e094ee148861e72e26c03e73d34a1/Formula/geos.rb.
  3. brew info geos应该显示 3.6.1 加星标: 在此处输入图片说明

回答by Tony Aziz

I fixed the issue by installing PostGIS with Postgres using https://postgresapp.com/downloads.html.

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

  1. Install PostGIS (2.2): brew install postgis
  2. To unlink geos if version is higher than 3.6.1: brew unlink geos
  3. Install Geos (3.6.1): brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/145b22e8330e094ee148861e72e26c03e73d34a1/Formula/geos.rb
  4. Switch geos version(latest version is 3.7.2 which is not supported by Django 1.11.3): brew switch geos 3.6.1
  5. Login to database and create postgis extensions: CREATE EXTENSION postgis; Test postgis extension: SELECT ST_Distance('LINESTRING(-122.33 47.606, 0.0 51.5)'::geography, 'POINT(-21.96 64.15)'::geography);
  6. Check postgis version: SELECT PostGIS_full_version();
  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();

回答by RobM

Brew just released geos 3.8.0 that of course breaks Django 1.11 again. The previous version, 3.7.3, was oh so very helpfully cleared by the all new all automatic cleanup now running on upgrades, so no brew switch geos 3.7.3for me.

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

I ended up using this postto understand how to find the previous version number and commit hash:

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

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

After all this, the download for geos 3.7.3 fails SHA256 checksum validation for some reason... so I ended up trying 3.7.2, that actually worked.

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

For now the command to reinstall 3.7.2 on Catalina is:

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

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