2

I am trying to setup Geodjango 1.8 in a virtualenv with Python 2.7.9 (Win32).

I have installed and setup Postgres/PostGis and have my Path setup to my OSGeo4W directory. I have also installed the required Python bindings.

When I try to 'runserver' (to start the development server), I get the follow error:

    ...
    from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
    File "C:\Users\Matt\Envs\django_venv\lib\site-packages\django\contrib\gis\gdal
    \prototypes\raster.py", line 24, in <module>
    register_all = void_output(lgdal.GDALAllRegister, [])
    File "C:\Python27\Lib\ctypes\__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
    File "C:\Python27\Lib\ctypes\__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
    AttributeError: function 'GDALAllRegister' not found

I am able to start the development server in an app that doesn't use 'django.contrib.gis'.

My Settings.py:

DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'leaflet_map',
'djgeojson',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'webmaps.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'webmaps.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'db',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'
3

EDIT : The bug was reported to Django's team, they fixed it in the last stable release.

I faced the same issue, which seems to be related to the integration of the raster module in django 1.8's gis extension.

I think I found where the problem comes from. Looking at django.contrib.gis.gdal.libgal, you can see this:

..|
47|  # This loads the GDAL/OGR C library
48|  lgdal = CDLL(lib_path)
49| 
50|  # On Windows, the GDAL binaries have some OSR routines exported with
51|  # STDCALL, while others are not.  Thus, the library will also need to
52|  # be loaded up as WinDLL for said OSR functions that require the
53|  # different calling convention.
54|  if os.name == 'nt':
55|      from ctypes import WinDLL
56|    lwingdal = WinDLL(lib_path)
..|

So when the os is Windows, the GDAL library is also loaded as a DLL, so we have two GDAL libraries, lgdal and lwingdal.

But if you look at the django.contrib.gis.gdal.prototypes.raster (where the "'GDALAllRegister' not found" error is raised from), you can see that the one used is lgdal:

..|
29|  # Raster Driver Routines
30|  register_all = void_output(lgdal.GDALAllRegister, [])
31|  get_driver = voidptr_output(lgdal.GDALGetDriver, [c_int])
32|  get_driver_by_name = voidptr_output(lgdal.GDALGetDriverByName, [c_char_p], errcheck=False)
33|  get_driver_count = int_output(lgdal.GDALGetDriverCount, [])
34|  get_driver_description = const_string_output(lgdal.GDALGetDescription, [c_void_p])
..|

It seems like on Windows, lwingdal should be used, so I added this after the imports:

..|  
15|  # Fix for windows users
16|  if os.name == 'nt':
17|      from django.contrib.gis.gdal.libgdal import lwingdal 
18|      lgdal = lwingdal
..|  

And it solved the problem for me! Maybe there is something more, it seems a bit too easy, but I still had no issue with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.