Sqlite load_extension fail for spatialite in Python

MappaGnosis picture MappaGnosis · Dec 21, 2011 · Viewed 9.3k times · Source

I am trying to use the Spatialite beta version 3.0 because I am using Windows 7 on a 64-bit machine.

I consistently get the dreaded sqlite3.OperationalError: The specified module could not be found. error when I try to load libspatialite-4.dll.

I have tried the following:

  • put libspatialite-4.dll and all the other dlls in the same folder
  • use the full path to the dlls
  • add the dll location to the 'PATH' environment variable
  • append the dll location to the sys.path attribute as part of the Python code
  • copy all the dlls in the c:\windows\system32 folder (complete with restart of the machine)
  • copy all the dlls in the c:\windows\sysWoW64 folder (complete with restart of the machine this is supposed to be for 32 bit dlls but I tried it anyway)

my code is as follows:

import sqlite3
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.execute('SELECT load_extension("libspatialite-4.dll")')

NOTE - I have tried the full path too with no luck. I remember having the same problem with Windows XP 32-bit. I got it working but can't remember what I did :(

UPDATE

I have tested the setup on 32-bit Windows 7 and putting all the dlls in the System32 folder works. So, this suggests that there is some problem with the 64-bit setup. Could it be that I need another version of MSVC (I don't think the Spatialite website says which is necessary so I might just have to guess - I have MSVC2010 installed)?

Answer

Castrona picture Castrona · Jun 8, 2012

I was having the same problem and it confused me for days. I'm running Python 2.6 (32-bit) on Windows 7(x64), so it may not be the same setup as you have.

Here's what you can try (taken from this Google Groups post):

  1. Put the spatialite dlls (libgeos_c-1.dll, libgeos-3-0-0.dll, libproj-0.dll, and libspatialite-2.dll) into a folder on the C:/ drive.
  2. Add this folder to your PATH.

The problems seems to be that Windows may not load the dlls from C:\Windows\system32 because of user permissions settings.