2009-09-22 117 views
1

我试图安装pysqlite。一些可疑的事情在安装过程中开始出现。为什么我输入:为什么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的命令行模式I型

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”。预先感谢您的任何帮助。

+2

您知道SQLite支持位于标准库中吗?至少从蟒蛇版本2.5 – codeape

回答

2

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

检查sqlite的头部等

3

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

你不能忽略的最后一行。它告诉你有一个错误,所以无法编译。接下来的事情告诉你,它无法安装,因为它无法编译。然后,你的python告诉你它不能运行代码,因为它没有安装。在继续安装之前,您需要先完成编译步骤。

+0

行。但如何编译和安装?错误信息的含义是什么? – Verrtex

+0

不幸的是,我可能无法帮助您编译它。我能做的最好的事情是指出编译阶段失败了,任何过去的事情都没有解决问题。 – RHSeeger

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

相关问题