1

我试图安装 pysqlite。在安装过程中开始出现一些可疑的东西。为什么我输入:

python setup.py build

最后我收到以下消息:

src/module.c:286: error: ‘SQLITE_PRAGMA’ undeclared here (not in a function)
src/module.c:287: error: ‘SQLITE_READ’ undeclared here (not in a function)
src/module.c:288: error: ‘SQLITE_SELECT’ undeclared here (not in a function)
src/module.c:289: error: ‘SQLITE_TRANSACTION’ undeclared here (not in a function)
src/module.c:290: error: ‘SQLITE_UPDATE’ undeclared here (not in a function)
src/module.c:291: error: ‘SQLITE_ATTACH’ undeclared here (not in a function)
src/module.c:292: error: ‘SQLITE_DETACH’ undeclared here (not in a function)
src/module.c: In function ‘init_sqlite’:
src/module.c:419: warning: implicit declaration of function ‘sqlite3_libversion’
src/module.c:419: warning: passing argument 1 of ‘PyString_FromString’ makes pointer from integer without a cast
error: command 'gcc' failed with exit status 1

我只是忽略了最后一行并决定继续。所以,我输入:

python setup.py install

而且,我再次收到类似的错误消息:

src/module.c:288: error: ‘SQLITE_SELECT’ undeclared here (not in a function)
src/module.c:289: error: ‘SQLITE_TRANSACTION’ undeclared here (not in a function)
src/module.c:290: error: ‘SQLITE_UPDATE’ undeclared here (not in a function)
src/module.c:291: error: ‘SQLITE_ATTACH’ undeclared here (not in a function)
src/module.c:292: error: ‘SQLITE_DETACH’ undeclared here (not in a function)
src/module.c: In function ‘init_sqlite’:
src/module.c:419: warning: implicit declaration of function ‘sqlite3_libversion’
src/module.c:419: warning: passing argument 1 of ‘PyString_FromString’ makes pointer from integer without a cast
error: command 'gcc' failed with exit status 1

之后,我想尝试 pysqlite 是否有效。如果在 python 命令行模式下我输入

from pysqlite2 import *

Python 没有抱怨。但是,如果我尝试按照书中的示例进行操作:

from pysqlite2 import dbapi2 as sqlite

我收到一条错误消息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pysqlite2/dbapi2.py", line 27, in <module>
    from pysqlite2._sqlite import *
ImportError: No module named _sqlite

有没有人知道为什么会发生这种情况以及如何解决这个问题。顺便说一句,我已经安装了新版本的 Python。“python -V”给了我“Python 2.6.2”。预先感谢您的任何帮助。

4

3 回答 3

3

我只是忽略了最后一行并决定继续。

你不能只忽略最后一行。它告诉你有一个错误,所以它无法编译。您运行的下一件事告诉您它无法安装,因为它无法编译。然后,您的 python 告诉您它无法运行代码,因为它没有安装。在继续安装之前,您需要让编译步骤正常工作。

于 2009-09-22T13:41:09.763 回答
2

需要上一堂编译 python 扩展的课程,您使用的是哪个发行版?您似乎缺少具有给定宏定义的 sqlite 标头。当 python 安装程序运行时,它编译绑定到 sqlite 本机二进制文件并将一些 .py 文件复制到库中。_sqlite 通常是一个 .pyd 文件(相当于一个 dll),它调用了 sqlite 库,在您的情况下,它没有被构建。

检查 sqlite 标头等的存在。

于 2009-09-22T14:04:18.143 回答
2

构建 pysqlite 的正确方法现在在网站上。

$ tar xvfz <version>.tar.gz 
$ cd <version> 
$ python setup.py build_static install 

build_static 将下载最新的 sqlite 代码并对其进行静态编译。需要注意的是,我只是在 1and1 共​​享主机上执行此操作。

http://trac.edgewall.org/wiki/PySqlite#Buildingpysqlite

于 2010-11-19T04:30:21.963 回答