Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

python - GeoDjango on Windows: Try setting GDAL_LIBRARY_PATH in your settings

I've done this a dozen times before, but something isn't working this time..

Following the docs:

https://docs.djangoproject.com/en/1.11/ref/contrib/gis/install/#windows

I'm trying to set up GeoDjango on a Windows machine (this one is a virtual windows 10 set up on paperspace.com). There seems to be a problem with my PATH settings, but I can't figure out what it is. I've run the commands highlighted in the instructions. I've checked my PATH variables and everything seems ok. I've tried pointing them to both the 32-bit and 64-bit versions of OSGeo4Win. Regardless, I get the following output every time:

C:Pythonlibsite-packagesfloppyforms\__init__.py:21: UserWarning: Unable to import floppyforms.gis, geometry widgets not available
  "Unable to import floppyforms.gis, geometry widgets not available")
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:Pythonlibsite-packagesdjangocoremanagement\__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "C:Pythonlibsite-packagesdjangocoremanagement\__init__.py", line 337, in execute
    django.setup()
  File "C:Pythonlibsite-packagesdjango\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:Pythonlibsite-packagesdjangoapps
egistry.py", line 108, in populate
    app_config.import_models()
  File "C:Pythonlibsite-packagesdjangoappsconfig.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "C:Pythonlibimportlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "C:Pythonlibsite-packagesdjangocontribauthmodels.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "C:Pythonlibsite-packagesdjangocontribauthase_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "C:Pythonlibsite-packagesdjangodbmodelsase.py", line 124, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "C:Pythonlibsite-packagesdjangodbmodelsase.py", line 330, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:Pythonlibsite-packagesdjangodbmodelsoptions.py", line 214, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "C:Pythonlibsite-packagesdjangodb\__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:Pythonlibsite-packagesdjangodbutils.py", line 211, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:Pythonlibsite-packagesdjangodbutils.py", line 115, in load_backend
    return import_module('%s.base' % backend_name)
  File "C:Pythonlibimportlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:Pythonlibsite-packagesdjangocontribgisdbackendspostgisase.py", line 5, in <module>
    from .features import DatabaseFeatures
  File "C:Pythonlibsite-packagesdjangocontribgisdbackendspostgisfeatures.py", line 1, in <module>
    from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
  File "C:Pythonlibsite-packagesdjangocontribgisdbackendsasefeatures.py", line 4, in <module>
    from django.contrib.gis.db.models import aggregates
  File "C:Pythonlibsite-packagesdjangocontribgisdbmodels\__init__.py", line 3, in <module>
    from django.contrib.gis.db.models.aggregates import *  # NOQA
  File "C:Pythonlibsite-packagesdjangocontribgisdbmodelsaggregates.py", line 1, in <module>
    from django.contrib.gis.db.models.fields import ExtentField
  File "C:Pythonlibsite-packagesdjangocontribgisdbmodelsfields.py", line 3, in <module>
    from django.contrib.gis import forms, gdal
  File "C:Pythonlibsite-packagesdjangocontribgisforms\__init__.py", line 3, in <module>
    from .fields import (  # NOQA
  File "C:Pythonlibsite-packagesdjangocontribgisformsfields.py", line 4, in <module>
    from django.contrib.gis.geos import GEOSException, GEOSGeometry
  File "C:Pythonlibsite-packagesdjangocontribgisgeos\__init__.py", line 5, in <module>
    from .collections import (  # NOQA
  File "C:Pythonlibsite-packagesdjangocontribgisgeoscollections.py", line 11, in <module>
    from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
  File "C:Pythonlibsite-packagesdjangocontribgisgeosgeometry.py", line 11, in <module>
    from django.contrib.gis import gdal
  File "C:Pythonlibsite-packagesdjangocontribgisgdal\__init__.py", line 28, in <module>
    from django.contrib.gis.gdal.datasource import DataSource
  File "C:Pythonlibsite-packagesdjangocontribgisgdaldatasource.py", line 39, in <module>
    from django.contrib.gis.gdal.driver import Driver
  File "C:Pythonlibsite-packagesdjangocontribgisgdaldriver.py", line 5, in <module>
    from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
  File "C:Pythonlibsite-packagesdjangocontribgisgdalprototypesds.py", line 9, in <module>
    from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
  File "C:Pythonlibsite-packagesdjangocontribgisgdallibgdal.py", line 44, in <module>
    'GDAL_LIBRARY_PATH in your settings.' % '", "'.join(lib_names)
django.contrib.gis.gdal.error.GDALException: Could not find the GDAL library (tried "gdal111", "gdal110", "gdal19", "gdal18", "gdal17"). Try setting GDAL_LIBRARY_PATH in your settings.

Does anyone have any ideas?

UPDATE: I went to the store and bought a new laptop and I am still running into the same issue. Could it be an versioning issue with some of the GeoDjango dependencies? I'm at a loss for what to do, but it's kind of an emergency for me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The issue ended up being a version mismatch between Django and GDAL. Django was not searching for the correct file name (gdal202.dll in my case).

Fixing it required me to add str('gdal202') to the following file on line 26:

(Python Root)Libsite-packagesdjangocontribgisgdallibgdal.py

Note that if you are working in a Virtual Environment, then Python Root will actually be wherever that is ie: UsersYourNameEnvsproject

If this issue reoccurs, you can look through your C:OSGeo4Win directory to figure out which gdalxxx.dll it is that Django needs to search for.

In addition, make sure that you are using the 32-bit versions of Python and OSGeo4Win. Otherwise, you may see the same failure.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...