错误是:无法在Windows 8.1中导入名称“GDALRaster”

时间:2017-04-30 14:02:59

标签: django postgis

 It's not my answer. Because I am trying to develop in windows 8.1 64bit: http://stackoverflow.com/questions/39037351/django-migration-cant-find-gdalraster

(casino_locater) C:\Users\....\Desktop\Geolocation>python manage.py makemigrations
.............
..............
..............
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'postgresql', 'sqlite3'
Error was: cannot import name 'GDALRaster'

1 个答案:

答案 0 :(得分:1)

 
Only for window users: 
Follow the below steps to install gdal into the window environment: 

Step 1: Install OSGeo4W

The OSGeo4W installer makes it simple to install the PROJ.4, GDAL, and GEOS libraries required by GeoDjango. First, download the OSGeo4W installer, and run it. 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, but are not required by GeoDjango and may be unchecked safely. After clicking next, the packages will be automatically downloaded and installed, after which you may exit the installer.

for 32bit: http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86.exe
for 64bit: http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86_64.exe

Step 2: Modify Windows environment

In order to use GeoDjango, you will need to add your Python and OSGeo4W directories to your Windows system Path, as well as create GDAL_DATA and PROJ_LIB environment variables. The following set of commands, executable with cmd.exe, will set this up:
`set OSGEO4W_ROOT=C:\OSGeo4W set PYTHON_ROOT=C:\Python27 set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal set PROJ_LIB=%OSGEO4W_ROOT%\share\proj set PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%\bin reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /f /d "%PATH%" reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v GDAL_DATA /t REG_EXPAND_SZ /f /d "%GDAL_DATA%" reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROJ_LIB /t REG_EXPAND_SZ /f /d "%PROJ_LIB%" `

Copy (without single inverted commas) the above script into notepad or any text editor and save the file name by geodjango_setup.bat 

Note: 1 

Administrator privileges are required to execute these commands. To do this, right-click on geodjango_setup.bat and select Run as administrator. You need to log out and log back in again for the settings to take effect.

Note: 2

If you customised the Python or OSGeo4W installation directories, then you will need to modify the OSGEO4W_ROOT and/or PYTHON_ROOT variables accordingly. 

For more details : https://docs.djangoproject.com/en/1.10/ref/contrib/gis/install/#windows