I'm working on a GIS project, and I would like to implement and test some geo-spatial algorithms in Python. For this purpose, I will not only need SQLite, but also SpatiaLite, in order to store and query the location data. Now I've tried to install the pyspatialite package, but no matter what Python version I tried (I tried all versions from 2.6 to 3.3), the pip keeps insisting, that none of the existing pyspatialite packages are compatible with my version of Python which is 2.6.6.
If I try to do this using easy_install, I get a traceback and an error:
AttributeError: MSVCCompiler instance has no attribute 'compiler'
And that also occurs, if I try to install the package manually, by executing the setup.py file.
From what I've already searched, some people suggest to connect to a SpatiaLite database somehow using SQLite and loading extension, but frankly I have no idea how to do it, and couldn't understand any of these answers.
Are you able to propose a solution in a clear, step-by step way?
I'm not a very experienced Python programmer yet.
Another attempt, this time with Python 3.3.5. The following code:
import sqlite3
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.execute('SELECT load_extension("libspatialite-2.dll")')
yields:
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
conn.execute('SELECT load_extension("libspatialite-2.dll")')
sqlite3.OperationalError: %1 is not a valid Win32 application.
And again, I don't seem able to resolve this on my own.
The error above was due to something else, I reinstalled Python and pysqlite, and we are back with the old error. There are two options now:
I compile using from pysqlite2 import dbapi2 as sqlite3. In this case code is the following:
from pysqlite2 import dbapi2 as sqlite3 conn = sqlite3.connect(":memory:") conn.enable_load_extension(True) conn.execute('SELECT load_extension("DLLs\libspatialite-4.dll")') curs = conn.cursor()
In that case, the error is:
Traceback (most recent call last):
File "C:\Users\mszydlowski\Desktop\Project\sqlite.py", line 3, in <module>
conn.enable_load_extension(True)
AttributeError: 'pysqlite2.dbapi2.Connection' object has no attribute 'enable_load_extension'
I compile using import sqlite3. In this case code is the following:
import sqlite3 conn = sqlite3.connect(":memory:") conn.enable_load_extension(True) conn.execute('SELECT load_extension("DLLs\libspatialite-4.dll")') curs = conn.cursor()
And the error:
Traceback (most recent call last):
File "C:\Users\mszydlowski\Desktop\Project\sqlite.py", line 4, in <module>
conn.execute('SELECT load_extension("DLLs\\libspatialite-4.dll")')
OperationalError: The specified module could not be found.
even though the file is certainly in there, and I did use the double backslashes, like I was already advised.