我一直在try 设置我的windows计算机,这样我就可以拥有一个带有PostGIS扩展的本地postgreSQL.安装了它之后,我希望能够在将其放入云中之前,在本地创建一个geodjango项目.我已经在本地机器上与Django合作了一段时间,使用了SQLite DB,但由于下一个项目将部分基于基于坐标的数据,我想设置正确的环境.

Import note: I've installed mini-conda to run in a seperate environment. I do activate this environment "development" when I work though

我试着在网上关注geodjango的大部分信息/教程,但都没能成功.我所做的(主要是以下内容:https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows):

  1. https://www.enterprisedb.com/downloads/postgres-postgresql-downloads下载并安装最新(10.3)的PostgreSQL安装程序
  2. 安装后,我还使用应用程序堆栈生成器安装了PostGis
  3. 我已经安装了https://trac.osgeo.org/osgeo4w/台OSGeo4W
  4. 我已经按照geodjango网站(https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows)上的描述创建了一个批处理脚本,并以管理员的身份运行了它(除了设置python路径的部分,因为自从我使用python一段时间以来,python已经在那里了)
  5. 我在psql shell中try 了一些命令,我想我已经创建了一个名为geodjango、用户名:***和pass:***的数据库.
  6. 我不知道我是否给了geodjango用户所有特权,但我怀疑是这样.

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

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

我在设置中也有这个.py:

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

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

当我try 在django中设置数据库时,我运行(在正确的文件夹中):

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.

我试着解决这个问题,但似乎没有任何效果.

2018年7月3日更新:

Now 我得到以下错误:

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

(当.dll存在时…)

推荐答案

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

  • 运行python判断python是32位还是64位.
  • Install corresponding OSGeo4W (32 or 64 bit) into C:\OSGeo4W or C:\OSGeo4W64:
    • Note: Select Express Web GIS安装,然后单击下一步.
    • 在" Select 软件包"列表中,确保选中了GDAL;默认情况下,MapServer和Apache也处于启用状态,可以安全地取消选中.
  • 确保您的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是否正常工作.

Postgresql相关问答推荐

无法在PostgreSQL中创建方案和表

DBT-DBT依赖于未找到的源

自左联接的POSTGIS更新

表示 SQL 表的 Go struct

Postgres 转储按顺序插入

在 jOOQ 中 Select 相同的命名列

Rails Migration 使用转换将字符串转换为整数

PostgreSQL:please specify covering index name是什么意思

Nodejs应用程序的node-postgres vs pg-promise

PostgreSQL ORDER BY 问题 - 自然排序

如何使用 SpringBoot + JPA 存储 PostgreSQL jsonb?

PostgreSQL如何连接间隔值'2天'

datagrip 无法应用更改 此表是只读的

如何使用字符串作为 PostgreSQL 咨询锁的键?

返回 NULL 的空数组的 array_length()

在 postgreSQL 中更改序列名称

错误:must be owner of language plpgsql

如何使用 PostgreSQL 触发器来存储更改(SQL 语句和行更改)

psql 将默认 statement_timeout 设置为 postgres 中的用户

如何使用 postgresql 按计数排序?