Reputation: 1404
I am using Windows7 to develop a GeoDjango app, my Python version is 3.3. Following the steps from Django documentation, I installed Postgresql9.1 and Postgis extension. Then when I am installing gdal library, there is a problem. I install the gdal from
http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
which it says it has all the required files. But for me, I can not correctly set it up. I test it with
from django.contrib.gis import gdal
and the following errors prompt out:
>>> from django.contrib.gis import gdal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\python33\lib\site-packages\django\contrib\gis\gdal\__in
it__.py", line 41, in <module>
from django.contrib.gis.gdal.driver import Driver
File "C:\Program Files\python33\lib\site-packages\django\contrib\gis\gdal\driv
er.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as capi
File "C:\Program Files\python33\lib\site-packages\django\contrib\gis\gdal\prot
otypes\ds.py", line 8, in <module>
from django.contrib.gis.gdal.libgdal import lgdal
File "C:\Program Files\python33\lib\site-packages\django\contrib\gis\gdal\libg
dal.py", line 47, in <module>
lgdal = CDLL(lib_path)
File "C:\Program Files\python33\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application。
>>>
So I check the file of libgdal.py in python3.3, and I find there is no lib name for gdal1.10, as from the following code:
elif os.name == 'nt':
# Windows NT shared libraries
lib_names = ['gdal19', 'gdal18', 'gdal17', 'gdal16', 'gdal15']
so I change it to
elif os.name == 'nt':
# Windows NT shared libraries
lib_names = ['gdal110', 'gdal19', 'gdal18', 'gdal17', 'gdal16', 'gdal15']
why I did this is because I find the gdal installed a 'gdal110.dll' file within my python site-package folder.
C:\Program Files\python33\Lib\site-packages\osgeo
However, this modification doesn't work either.
Then I tried to add this line to my settings.py of Django.
GDAL_LIBRARY_PATH = 'C:\Program Files\python33\Lib\site-packages\osgeo\gdal110.dll'
it still does not work, the error message was as before.
Can anyone point me a way out?
Upvotes: 2
Views: 2455
Reputation: 1404
The problem has settled, I used the accepted answer from
Unable to install Python and GDAL (DLL load failed)
and it workds, what I did before this, is to rename my OSGeo4W folder(i.e. delete them). Now Django is able to find gdal from django.contrib.gis.
Upvotes: 3