[Django]-GeoDjango: cannot import name GEOSException fixed, now [WinError 126]

3👍

I was able to fix the problem. See what I did here:

Django forum with how I fixed it

Sorry, this error message is obscure. I have filed a ticket to improve
it: https://code.djangoproject.com/ticket/23873

The cause of the error message is that you do not have an installation
of GEOS that is on your sys.path and importable. (That is, something
in
https://docs.djangoproject.com/en/1.7/ref/contrib/gis/install/#osgeo4w
or the following step didn’t work correctly.)

If you look in django/contrib/gis/geos/init.py, you’ll see that
GEOSException is only imported there if HAS_GEOS is True. That is why
importing GEOSException from django.contrib.gis.geos will succeed if you
have GEOS installed, but fails otherwise.

As for the win 126 error:

I am not sure exactly what helped finally fix it but:

  1. I changed my python version from 64 bit to 32 bit
  2. The script in that updated the path variables were pretty messed up, so I manually changed them to what they should have been.
  3. I had incorrectly added the GEOS_LIBRARY_PATH of

C:\program files\OSGeo4W\bin\geos_c.dll

but I should have added:

C:\OSGeo4W\bin\geos_c.dll

Now, I can just delete the GEOS_LIBRARY_PATH from the project settings and things still work, so I guess it must have been the 64 bit vs 32 bit issue, or the path issue.

Leave a comment