错误是:无法在 Windows 10 上为 GeoDjango 导入名称 'GDALRaster'

Error was: cannot import name 'GDALRaster' on Windows 10 for GeoDjango

我正在努力学习 GeoDjango 教程。我正在使用 windows-10 64 位计算机。我正在使用 Python 3.6 和 Django 1.11 我按照 GeoDjango Windows Documentation 安装。我已经成功完成了它告诉我的所有步骤我还下载了 运行 OSGeo4W 并成功 运行 我的 cmd.exe 中的路径作为管理员

现在回到 Django Tutorial

Create a Spatial Database: 我在我的 Postgres 中创建了一个数据库 Sql

我启动了一个名为 geodjango 的 Django 项目,启动了一个名为 world 的应用

我把设置里的数据库改成了

DATABASES = {
    'default': {
         'ENGINE': 'django.contrib.gis.db.backends.postgis',
         'NAME': 'geodjango',
         'USER': 'geo',
    },
}

我在 settings.py 安装的应用程序

中添加了以下内容
'django.contrib.gis',
'world',

我在 world 应用程序中创建了一个名为 data 的目录。我下载了 zip 文件并将其解压缩到我的数据文件夹中。我的数据文件夹中有以下文件

Use ogrinfo to examine spatial data(我不知道该怎么做,所以我忽略了这部分)

我成功地制作了 models.py 就像 tutorial

中所说的那样
from django.contrib.gis.db import models

class WorldBorder(models.Model):
    # Regular Django fields corresponding to the attributes in the
    # world borders shapefile.
    name = models.CharField(max_length=50)
    area = models.IntegerField()
    pop2005 = models.IntegerField('Population 2005')
    fips = models.CharField('FIPS Code', max_length=2)
    iso2 = models.CharField('2 Digit ISO', max_length=2)
    iso3 = models.CharField('3 Digit ISO', max_length=3)
    un = models.IntegerField('United Nations Code')
    region = models.IntegerField('Region Code')
    subregion = models.IntegerField('Sub-Region Code')
    lon = models.FloatField()
    lat = models.FloatField()

    # GeoDjango-specific: a geometry field (MultiPolygonField)
    mpoly = models.MultiPolygonField()

    # Returns the string representation of the model.
    def __str__(self):              # __unicode__ on Python 2
        return self.name

然后教程要求我 运行 python manage.py makemigrations 当我这样做时我得到以下错误

Error was: cannot import name 'GDALRaster'

我该如何解决这个错误

我试过了

pip install gdal 

这给了我一个错误

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools 

所以我下载了 Microsoft Visual C++ Build Tools。并尝试 运行

 pip install gdal 

再次出现错误

`error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe' failed with exit statu
s 2`

尝试 almost 一切之后。我通过虚拟框将我的 os 从 windows 移动到 Linux Ubuntu 18(Udemy 课程学习 Ubuntu)然后简单地做了

sudo apt install geos sudo apt 安装 prog4 sudo apt 安装 gdal

安装了 postgres sql 和 pgadmin3(pg admin 4 到今天 ubuntu 还不容易安装)使数据库名为 'geodjango'然后使用 pgadmin3 sudo apt install postgis

然后安装 pip psycopg2 和 dj-数据库-url

我建议远离 make 和 make install 方法,它们花费的时间太长并且总是会抛出错误。在此之后 GeoDjango tutorial 变得轻而易举