SQLite load_extension对于Python中的spacealite失败 [英] Sqlite load_extension fail for spatialite in Python
问题描述
我正在尝试使用Spatialite beta 3.0版,因为我正在使用 64位计算机上的Windows 7.
I am trying to use the Spatialite beta version 3.0 because I am using Windows 7 on a 64-bit machine.
当我尝试加载时,始终出现可怕的sqlite3.OperationalError: The
specified module could not be found.
错误
libspatialite-4.dll
.
I consistently get the dreaded sqlite3.OperationalError: The
specified module could not be found.
error when I try to load
libspatialite-4.dll
.
我尝试了以下操作:
- 将
libspatialite-4.dll
和所有其他dll放在同一文件夹中 - 使用dll的完整路径
- 将dll位置添加到
'PATH'
环境变量 - 将dll位置附加到sys.path属性中,作为Python代码的一部分
- 复制
c:\windows\system32
文件夹中的所有dll(在重新启动计算机后完成) - 复制
c:\windows\sysWoW64
文件夹中的所有dll(在重新启动计算机后完成,这应该是针对32位dll的,但我还是尝试过了)
- put
libspatialite-4.dll
and all the other dlls in the same folder - use the full path to the dlls
- add the dll location to the
'PATH'
environment variable - append the dll location to the sys.path attribute as part of the Python code
- copy all the dlls in the
c:\windows\system32
folder (complete with restart of the machine) - copy all the dlls in the
c:\windows\sysWoW64
folder (complete with restart of the machine this is supposed to be for 32 bit dlls but I tried it anyway)
我的代码如下:
import sqlite3
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.execute('SELECT load_extension("libspatialite-4.dll")')
注意-我也尝试过完整的方法,但是没有运气.我记得有 Windows XP 32位版也有同样的问题.我知道了,但是不能 记得我做了什么:(
NOTE - I have tried the full path too with no luck. I remember having the same problem with Windows XP 32-bit. I got it working but can't remember what I did :(
更新
我已经在32位Windows 7上测试了安装程序,并将所有dll放入System32文件夹中都可以工作.因此,这表明64位设置存在一些问题.可能是我需要另一个版本的MSVC(我不认为Spatialite网站说这是必需的,所以我可能不得不猜测-我已经安装了MSVC2010)?
I have tested the setup on 32-bit Windows 7 and putting all the dlls in the System32 folder works. So, this suggests that there is some problem with the 64-bit setup. Could it be that I need another version of MSVC (I don't think the Spatialite website says which is necessary so I might just have to guess - I have MSVC2010 installed)?
推荐答案
我遇到了同样的问题,使我困惑了好几天.我正在Windows 7(x64)上运行Python 2.6(32位),因此它的设置可能与您的设置不同.
I was having the same problem and it confused me for days. I'm running Python 2.6 (32-bit) on Windows 7(x64), so it may not be the same setup as you have.
这就是您可以尝试的方法(摘录自此 Google网上论坛帖子):
Here's what you can try (taken from this Google Groups post):
- 将spacespaceite dll(libgeos_c-1.dll,libgeos-3-0-0.dll,libproj-0.dll和libspatialite-2.dll)放入C:/驱动器上的文件夹中.
- 将此文件夹添加到您的PATH中.
问题似乎是Windows可能由于用户权限设置而无法从C:\ Windows \ system32加载dll.
The problems seems to be that Windows may not load the dlls from C:\Windows\system32 because of user permissions settings.
这篇关于SQLite load_extension对于Python中的spacealite失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!