Python Forum
Load spatialite in Python 3.6 on Win10 failed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Load spatialite in Python 3.6 on Win10 failed
#1
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 
Reply
#2
Problem is solved.

See http://blog.jrg.com.br/2016/04/25/Fixing...g-problem/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Failed attempts to load Microsoft Appstore Python DLLs piyushd 0 431 Oct-31-2023, 10:43 AM
Last Post: piyushd
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,623 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  Where does pip auto install on Win10 with py 3.9.4? Fran_3 4 3,519 May-05-2021, 03:47 PM
Last Post: snippsat
  DLL load failed flaviu2 5 4,103 Oct-01-2020, 02:05 PM
Last Post: snippsat
  Compiling on win10 ebolisa 1 1,754 Sep-04-2020, 04:39 PM
Last Post: ebolisa
  How to load log.txt directly into python codes? sparkt 6 2,985 Aug-21-2020, 03:51 PM
Last Post: sparkt
  ImportError:DLL Load Failed after importing scipy.sparse.linalg sea_jam 0 2,356 Jul-31-2020, 01:54 AM
Last Post: sea_jam
  Load table from Oracle to MYSQL using python himupant94 0 1,642 May-12-2020, 04:50 PM
Last Post: himupant94
  Python - help with getting JSON from one DB and load to another DB qIekm 4 3,272 Apr-16-2020, 07:07 AM
Last Post: qIekm
  Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesyste jiapei100 0 10,142 Feb-11-2020, 01:27 PM
Last Post: jiapei100

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020