Python Forum

Full Version: Load spatialite in Python 3.6 on Win10 failed
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I’ve a problem with Python and sqlite/spatialite on Windows 10.

I’m writing a small Python module to interact with a spatialite database.
The development was originally done on Windows 7
I used following configuration:
  • Windows 7
  • Python 3.6.4
  • Sqlite 3.22
  • Spatialite 4.3.0a

All 64bit

The module works fine on Windows 7
But is doesn’t work on Windows 10 (Same configuration as uses on the Win7 machine). Checked on several machines.
Loading the Spatialite extension fails with this message:
Error:
Traceback (most recent call last): File "testScript.py", line 16, in <module> con.execute("select load_extension('mod_spatialite')") sqlite3.OperationalError: Das System kann die angegebene Datei nicht finden.
The german term means: The systen cannot find the file

I’ve done several instigations
I’m pretty sure that I can exclude the fowling problems:
  • Spatialite dll or one of the subordinate dll is not found (checked with process monitor)
  • Other files than expected are used (Sqlite and Spatialite)
  • I found no evidence there is a general problem with sqlite, spatialite and Windows 10

During my investigations I figured out something strange
On my Windows 10 machine OSGeo4W (64bit) is installed too. OSGeo4W has its own Python installation.
There are two ways of invoking Python 3 in OSGeo4W
  1. python3
  2. python

The strange thing is, that python3 works and python not.
The error message with python is different to the standard installation:

Error:
Traceback (most recent call last): File "testScript.py", line 16, in <module> con.execute("select load_extension('mod_spatialite')") sqlite3.OperationalError: Eine DLL-Initialisierungsroutine ist fehlgeschlagen.
The german term means: A DLL initialisation routine failed

I’m completely confused.
Does anybody have an idea what happen here?
What is the difference between python and python3?
Any ideas how to make it run on Win 10 with the standard Python installation

Thanks in advanced
import sqlite3
import os

con = sqlite3.connect(":memory:")

cur = con.cursor()

rs = cur.execute('select sqlite_version()')
for row in rs:
    print(("SQLite Version: %s") % (row[0]))
rs.close

con.enable_load_extension(True)
splpath = 'C:\\Users\\timm\\Downloads\\mod_spatialite-4.3.0a-win-amd64'
os.environ['PATH'] = splpath + ';' + os.environ['PATH']
con.execute("select load_extension('mod_spatialite')")
#con.load_extension('mod_spatialite')

rs = cur.execute('select spatialite_version()')
for row in rs:
    print(("Spatialite Version: %s") % (row[0]))
rs.close