178👍
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.
The error says:
GEOSException: Could not parse version info string “3.4.2-CAPI-1.8.2 r3921”
And the geos_version_info warns:
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’
Edit this file: site-packages/django/contrib/gis/geos/libgeos.py
Look for the function: geos_version_info
And change this line:
ver = geos_version().decode()
With this line:
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 '
23👍
In the latest GEOS install, the above answer didn’t work… but was close to the problem.
I changed the regex right above the geos_version_info():
from:
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.
- [Django]-Why does django's prefetch_related() only work with all() and not filter()?
- [Django]-Remove pk field from django serialized objects
- [Django]-Setting the selected value on a Django forms.ChoiceField
15👍
I think this is broken again. A recent upgrade on our FreeBSD server led to this error:
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.py
needs to be updated again to account for this different syntax. Nachopro’s solution still serves as a workaround.
- [Django]-Django storages aws s3 delete file from model record
- [Django]-Python Django Rest Framework UnorderedObjectListWarning
- [Django]-How to get a favicon to show up in my django app?
5👍
It appears that this has been fixed in Django as of last March or so. See also Django bug 20036. So upgrading to Django 1.5.4 will solve the problem.
- [Django]-How to import csv data into django models
- [Django]-Pycharm error Django is not importable in this environment
- [Django]-Getting Values of QuerySet in Django
- [Django]-How to use Python type hints with Django QuerySet?
- [Django]-Limit foreign key choices in select in an inline form in admin
- [Django]-Using a UUID as a primary key in Django models (generic relations impact)
4👍
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.3
for me.
I ended up using this post to 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.
For now the command to reinstall 3.7.2 on Catalina is:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/823b700ab61eeec57f34d50be2cc34a285fb5abc/Formula/geos.rb
- [Django]-What is the Simplest Possible Payment Gateway to Implement? (using Django)
- [Django]-How do you use the django-filter package with a list of parameters?
- [Django]-Check if OneToOneField is None in Django
2👍
If one cannot for any reason edit the site packages themselves, this ugly hack did it for me without having to act on the environment itself:
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)
It is based on JayCrossler’s answer.
Update
The above executes code found within the django.contrib.gis.geos.__init__.py
module, which already tries to use the problematic part, rendering the above solution unusable (for python 2.7+). This can be worked around as:
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)
Where basically we are acting directly on the module in sys.modules
instead of trying to get it from another import that will fail.
- [Django]-When should I use a custom Manager versus a custom QuerySet in Django?
- [Django]-Django edit user profile
- [Django]-Django – why is the request.POST object immutable?
- [Django]-How do I include image files in Django templates?
- [Django]-What is actually assertEquals in Python?
- [Django]-Django equivalent of SQL not in
1👍
I fixed the issue by installing PostGIS with Postgres using https://postgresapp.com/downloads.html.
- Install PostGIS (2.2): brew install postgis
- To unlink geos if version is higher than 3.6.1: brew unlink geos
- Install Geos (3.6.1): brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/145b22e8330e094ee148861e72e26c03e73d34a1/Formula/geos.rb
- Switch geos version(latest version is 3.7.2 which is not supported by Django 1.11.3): brew switch geos 3.6.1
- 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); - Check postgis version: SELECT PostGIS_full_version();
- [Django]-How to set the timezone in Django
- [Django]-How to change field name in Django REST Framework
- [Django]-Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet