首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么pysqlite不能正常工作?

为什么pysqlite不能正常工作?
EN

Stack Overflow用户
提问于 2009-09-22 13:34:18
回答 3查看 1.5K关注 0票数 1

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

代码语言:javascript
复制
python setup.py build

最后,我收到了以下消息:

代码语言:javascript
复制
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

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

代码语言:javascript
复制
python setup.py install

然后,再一次,我得到了类似的错误信息:

代码语言:javascript
复制
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-command-line模式下输入

代码语言:javascript
复制
from pysqlite2 import *

Python不会抱怨。然而,如果我尝试遵循我书中的一个例子:

代码语言:javascript
复制
from pysqlite2 import dbapi2 as sqlite

我收到一条错误消息:

代码语言:javascript
复制
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“给出了”Python2.6.2“。提前感谢您的帮助。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-09-22 14:04:18

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

检查是否存在sqlite标头等。

票数 2
EN

Stack Overflow用户

发布于 2009-09-22 13:41:10

我忽略了最后一行,决定继续。

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

票数 3
EN

Stack Overflow用户

发布于 2010-11-19 12:30:22

构建pysqlite的正确方法现在可以在网站上找到。

代码语言:javascript
复制
$ tar xvfz <version>.tar.gz 
$ cd <version> 
$ python setup.py build_static install 

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

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1460136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档