Il 2025-11-02 15:52 Sam Gothman ha scritto:
> New to spatialite and try to run the binaries in python. Unfortunately
> I don't succeed. What else needs to be installed so that spatialite
> works except from sqlite?
>
Hi Sam,
the canonical way to load SpatiaLite in Python is as follows:
1) First open a SQLite connection.
2) Then dynamically load the "mod_spatialite" extension module
by executing this SQLite command:
SELECT load_extension('mod_spatialite');
If all goes well, all Spatial SQL functions will be available
at this point, and then you can use them in the SQL queries
where the problems lie:you pass to SQLite.
Where the problems lie:
a) The dynamic extension module "mod_spatialite" must be located
in one of the standard directories where the operating system
and Python look for libraries (*.so on Linux, *.dll on Windows),
otherwise load_extension() will fail returning an error because
it's unable to locate the module to be loaded.
b) But all the many dependencies required by "mod_spatialite" must
also be loaded at the same time, otherwise the loading will fail
due to unresolved dependencies.
At this point it all depends on the operating system you are using.
On Linux it's all reasonably simple and easy, but on Windows it can
easily become a real nightmare, also because on this o.s. you will
receive very poor error messages that will not help you at all to
identify what exactly is preventing the extension module from loading.
To make installation less painful on Windows, you should download
this package, which certainly contains "mod_spatialite" with all
its dependencies:
https://www.gaia-gis.it/gaia-sins/windows-bin-amd64/mod_spatialite-5.1.0-win-amd64.7z
Note: all DLLs and other files in the package must be copied into
the same folder, which must of course be included in the standard
Windows and Python load paths.
If you continue to encounter problems, post a new message specifying
better which operating system you are working on, and possibly
include an example of the Python code that you use to load the
extension, including any error messages.
bye Sandro