Windows上的GeoDjango:尝试在您的设置中设置GDAL_LIBRARY_PATH

我已经做了十几次了,但是这个时候有些东西不行

遵循文档:

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

我试图在Windows机器上设置GeoDjango(这是在paperspace.com上设置的一个虚拟的Windows 10)。 我的PATH设置似乎有问题,但我不知道它是什么。 我已经运行了说明中突出显示的命令。 我检查了我的PATHvariables,一切似乎都没问题。 我试过将它们指向OSGeo4Win的32位和64位版本。 无论如何,我每次都得到以下输出:

C:\Python\lib\site-packages\floppyforms\__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:\Python\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line utility.execute() File "C:\Python\lib\site-packages\django\core\management\__init__.py", line 337, in execute django.setup() File "C:\Python\lib\site-packages\django\__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Python\lib\site-packages\django\apps\registry.py", line 108, in populate app_config.import_models() File "C:\Python\lib\site-packages\django\apps\config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "C:\Python\lib\importlib\__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:\Python\lib\site-packages\django\contrib\auth\models.py", line 4, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "C:\Python\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module> class AbstractBaseUser(models.Model): File "C:\Python\lib\site-packages\django\db\models\base.py", line 124, in __new__ new_class.add_to_class('_meta', Options(meta, app_label)) File "C:\Python\lib\site-packages\django\db\models\base.py", line 330, in add_to_class value.contribute_to_class(cls, name) File "C:\Python\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "C:\Python\lib\site-packages\django\db\__init__.py", line 33, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "C:\Python\lib\site-packages\django\db\utils.py", line 211, in __getitem__ backend = load_backend(db['ENGINE']) File "C:\Python\lib\site-packages\django\db\utils.py", line 115, in load_backend return import_module('%s.base' % backend_name) File "C:\Python\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "C:\Python\lib\site-packages\django\contrib\gis\db\backends\postgis\base.py", line 5, in <module> from .features import DatabaseFeatures File "C:\Python\lib\site-packages\django\contrib\gis\db\backends\postgis\features.py", line 1, in <module> from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures File "C:\Python\lib\site-packages\django\contrib\gis\db\backends\base\features.py", line 4, in <module> from django.contrib.gis.db.models import aggregates File "C:\Python\lib\site-packages\django\contrib\gis\db\models\__init__.py", line 3, in <module> from django.contrib.gis.db.models.aggregates import * # NOQA File "C:\Python\lib\site-packages\django\contrib\gis\db\models\aggregates.py", line 1, in <module> from django.contrib.gis.db.models.fields import ExtentField File "C:\Python\lib\site-packages\django\contrib\gis\db\models\fields.py", line 3, in <module> from django.contrib.gis import forms, gdal File "C:\Python\lib\site-packages\django\contrib\gis\forms\__init__.py", line 3, in <module> from .fields import ( # NOQA File "C:\Python\lib\site-packages\django\contrib\gis\forms\fields.py", line 4, in <module> from django.contrib.gis.geos import GEOSException, GEOSGeometry File "C:\Python\lib\site-packages\django\contrib\gis\geos\__init__.py", line 5, in <module> from .collections import ( # NOQA File "C:\Python\lib\site-packages\django\contrib\gis\geos\collections.py", line 11, in <module> from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin File "C:\Python\lib\site-packages\django\contrib\gis\geos\geometry.py", line 11, in <module> from django.contrib.gis import gdal File "C:\Python\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module> from django.contrib.gis.gdal.datasource import DataSource File "C:\Python\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 39, in <module> from django.contrib.gis.gdal.driver import Driver File "C:\Python\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module> from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi File "C:\Python\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module> from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal File "C:\Python\lib\site-packages\django\contrib\gis\gdal\libgdal.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. 

有没有人有任何想法?

更新:我去了商店,买了一台新的笔记本电脑,我仍然遇到同样的问题。 它可能是一些与GeoDjango依赖关系的版本问题? 我不知道该怎么做,但这对我来说是紧急的。

Solutions Collecting From Web of "Windows上的GeoDjango:尝试在您的设置中设置GDAL_LIBRARY_PATH"

这个问题最终导致了Django和GDAL之间的版本不匹配 。 Django没有搜索正确的文件名(在我的情况下是gdal202.dll )。

修复它需要我在第26行添加str('gdal202')到以下文件:

(Python Root)\Lib\site-packages\django\contrib\gis\gdal\libgdal.py

如果这个问题再次出现,你可以通过你的OSGeo4W\bin目录找出Django需要搜索哪个gdalxxx.dll