Use spatialite extension for SQLite on Windows

2019-01-19 22:21发布

问题:

I know that this has been asked in some similar ways before. However, all questions I found on this dealt with some very specific system setups which were not applicable for me (because so is mine).

System:

  • Windows 7 64bit
  • Python 3.4 64bit
  • sqlite3 2.6.0 (shipped with Python I guess)
  • Spatialite Windows binaries 2.3.1 (anything else of importance?)

How can I activate the spatialite extension for the ´sqlite3´ module?

What I tried (the way that other people in similar questions say it works):

  • Downloading from https://www.gaia-gis.it/spatialite-2.3.1/binaries.html :
    • libspatialite-win-x86-2.3.1.zip
    • proj-win-x86-4.6.1.zip
    • geos-win-x86-3.1.1.zip
    • libiconv-win-x86-1.9.2.zip
  • unzipping all of them into the same folder on C:\
  • (also tried only putting the DLLs into that folder)
  • putting that folder into my system PATH variable

Then, running

import sqlite3

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

gives

conn.execute("SELECT load_extension('libspatialite-2.dll')")
sqlite3.OperationalError: The specified module could not be found.

What more can I try to make this work?

回答1:

you probably don't have the folder in which libspatialite-2.dll is placed in your PATH. Perhaps you can add the folder from within your Python script (I don't know any Python). Or else you could add it from the Windows properties interface.

BTW you are using a very old version of spatialite: have a look here for newer versions: https://www.gaia-gis.it/fossil/libspatialite/index