Error was: cannot import name 'GDALRaster' in windows 8.1

旧巷老猫 提交于 2019-12-12 06:21:49

问题


 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:


 
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


来源:https://stackoverflow.com/questions/43707272/error-was-cannot-import-name-gdalraster-in-windows-8-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!