本文介绍了Windows上的GeoDjango:“找不到GDAL库"; /"OSError:[WinError 126]找不到指定的模块".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试设置Windows计算机,以便可以使用具有PostGIS扩展名的本地postgreSQL.安装此程序后,我希望能够在本地将geodjango创建项目后再将其放入云中.我已经在使用SQLite DB的本地计算机上与Django一起工作了一段时间,但是由于下一个项目将部分基于基于坐标的数据,所以我想设置正确的环境.

I've been trying to setup my windows computer such that I can have a local postgreSQL with PostGIS extension. With this installed I hope to be able to create a project with geodjango locally before putting it in the cloud. I have been working with Django for a little while now on my local machine with the SQLite DB, but since the next project will partly be based on coordinate based data I wanted to setup the right environment.

导入说明:我已经安装了mini-conda以便在单独的环境中运行.我在工作时确实会激活此环境开发"

我已尝试在线跟踪大多数geodjango信息/教程,但无法使其正常工作.我所做的(大多数情况是: https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows ):

I've tried to follow most of the geodjango information/tutorials online, but can't get it to work. What I've done (mostly followed this: https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows):

  1. https://www.enterprisedb下载并安装最新(10.3)PostgreSQL设置.com/downloads/postgres-postgresql-downloads
  2. 安装后,我还使用Application Stack Builder安装了PostGis
  3. 我已经从 https://trac.osgeo.org/osgeo4w/
  4. 我已经按照geodjango网站( https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows )并以管理员身份运行(除了将路径设置为python的部分,因为我已经使用python一段时间了,所以python已经在里面了
  5. 我在psql shell中尝试了一些命令,我​​想我已经创建了一个数据库,名称为:geodjango,用户名:****并通过:****.
  6. 我不知道是否已给geodjango用户所有特权,但我怀疑是这样.
  1. Download and install the latest (10.3) PostgreSQL setup from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
  2. After installation I also installed used the Application Stack Builder to install PostGis
  3. I've installed OSGeo4W from https://trac.osgeo.org/osgeo4w/
  4. I've created a batch script as described on the geodjango website (https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows) and ran it as administrator (except for the part where it sets the path to python, cause python was already in there since I've been using python for a while now)
  5. I've tried some command in psql shell and I think I've created a database with name: geodjango, username: **** and pass: ****.
  6. I don't know if I have given the geodjango user all priveleges, but I suspect so.

所有这些之后,我创建了一个新的django项目,并在settings.py中添加了一些部分:

After all of this I created a new django project and in settings.py I've added some parts:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'nameOfMyApp',
]

我也在settings.py中得到了这个

I've also got this in settings.py:

DATABASES = {
'default': {
    'ENGINE': 'django.contrib.gis.db.backends.postgis',
    'NAME': 'geodjango',
    'USER': '****',
    'PASSWORD': '****',
    'HOST': 'localhost',
}
}

# FOR GEODJANGO
POSTGIS_VERSION = (2, 4, 3)

当我尝试在Django中设置数据库时,我会运行(在正确的文件夹中):

When I try to set up the database in django I run (in the right folder):

python manage.py makemigrations

我收到以下错误:

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal202", "gdal201", "gdal20", "gdal111", "gdal110", "gdal19"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

我已尝试解决此问题,但似乎无济于事.有人可以帮我在本地进行所有设置吗?

I've tried to fix that, but nothing seems to work.Can anybody give me some help in setting this all up locally?

更新7-3-2018:

Update 7-3-2018:

  • I've tried installing GDAL manually myself, (from: http://www.gisinternals.com/query.html?content=filelist&file=release-1911-x64-gdal-2-2-3-mapserver-7-0-7.zip the generic core components)
  • I've installed (what I assume are) the python bindings from https://www.lfd.uci.edu/~gohlke/pythonlibs/. Still I get the same error.
  • I've also tried setting the GDAL_LIBRARY_PATH to the GDAL directory or the gdal-data directory (which resides in the GDAL directory).

现在出现以下错误:

OSError: [WinError 126] The specified module could not be found

(.dll在那里...)

(while the .dll is there...)

推荐答案

我发现以下内容适用于Windows:

I have found the following to work for windows:

  • 运行python来检查您的 python 是32位还是64位.
  • 将相应的 OSGeo4W (32或64位)安装到C:\OSGeo4WC:\OSGeo4W64中:
    • 注意::选择"Express Web-GIS安装",然后单击下一步".
    • 在选择软件包"列表中,确保已选择GDAL;默认情况下,MapServer和Apache也处于启用状态,可能会被安全地取消选中.
    • Run python to check if your python is 32 or 64 bit.
    • Install corresponding OSGeo4W (32 or 64 bit) into C:\OSGeo4W or C:\OSGeo4W64:
      • Note: Select Express Web-GIS Install and click next.
      • In the ‘Select Packages’ list, ensure that GDAL is selected; MapServer and Apache are also enabled by default, may be unchecked safely.

      确保以下内容包含在您的settings.py中:

      Make sure the following is included in your settings.py:

      import os
      if os.name == 'nt':
          import platform
          OSGEO4W = r"C:\OSGeo4W"
          if '64' in platform.architecture()[0]:
              OSGEO4W += "64"
          assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
          os.environ['OSGEO4W_ROOT'] = OSGEO4W
          os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
          os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
          os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']
      

    • 运行python manage.py check以验证geodjango是否正常工作.

    • Run python manage.py check to verify geodjango is working correctly.

      这篇关于Windows上的GeoDjango:“找不到GDAL库"; /"OSError:[WinError 126]找不到指定的模块".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:49
查看更多