2009-09-22 116 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

相關問題