代码之家  ›  专栏  ›  技术社区  ›  Samir Tendulkar

错误为:无法在Windows 10上为GeoDjango导入名称“gdalMaster”

  •  0
  • Samir Tendulkar  · 技术社区  · 7 年前

    我正在努力学习吉德扬戈的教程。我正在使用一台64位的windows-10计算机。我使用的是Python3.6和Django1.11 GeoDjango Windows Documentation 安装。我已经成功地完成了它告诉我的所有步骤,我还下载并运行了OSGeo4W,并以管理员身份成功地运行了cmd.exe中的路径

    enter image description here

    现在回到 Django Tutorial

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

    enter image description here

    我开始了一个叫Django的项目 吉德扬戈 ,启动了一个名为 世界

    我将设置中的数据库更改为

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

    我在我的settings.py安装的应用程序中添加了以下内容

    'django.contrib.gis',
    'world',
    

    我在 world 申请。我下载了zip文件并将其解压缩到我的数据文件夹中。我的数据文件夹中有以下文件 enter image description here

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

    我成功地 模型.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 
    

    所以我下载了微软Visual C++构建工具。试图逃跑

     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`
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Samir Tendulkar    7 年前

    在尝试了几乎所有的事情之后。我用Ubuntu18(Udemy课程学习Ubuntu)把我的操作系统从windows移到Linux,然后简单地

    sudo apt安装geos sudo apt安装程序4 sudo apt安装gdal

    安装了postgres sql和pgadmin3(pg admin 4从今天起在ubuntu上不容易安装)之后,使用pgadmin3在名为“geodjango”的数据库上创建了 sudo apt安装postgis

    然后安装pip 心理2和 dj数据库url

    我建议不要使用make&make-install方法,它们花费的时间太长,而且总是抛出错误。在这之后 GeoDjango tutorial 是一阵微风

    推荐文章