为什么 pysqlite 不能正常工作?

发布于 2024-08-05 00:00:33 字数 2326 浏览 9 评论 0原文

我尝试安装 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”。预先感谢您的帮助。

I tried to install pysqlite. Some suspicious things start to appear during the installation. Why I typed:

python setup.py build

I got the following message in the end:

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

I just ignored the last line and decided to continue. So, I typed:

python setup.py install

And than, again, I got similar error message:

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

After that I wanted to try if pysqlite works.
If in the python-command-line mode I type

from pysqlite2 import *

Python does not complain. However, if I try to follow an exmaple in my book:

from pysqlite2 import dbapi2 as sqlite

I get a error message:

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

Does anybody have any ideas why it happens and how this problem can be solved. By the way, I have installed a new version of Python. "python -V" gives me "Python 2.6.2". Thank you in advance for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉世弥音 2024-08-12 00:00:33

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

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

I just ignored the last line and decided to continue.

You can't just ignore the last line. It was telling you there was an error, so it couldn't compile. The next thing you ran told you it couldn't install because it couldn't compile. Then, your python told you it couldn't run the code because it wasn't installed. You need to get the compile step working before you move on to installing it.

梦行七里 2024-08-12 00:00:33

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

检查 sqlite 标头等是否存在。

A lesson in compiling python extensions is needed, which distribution are you using ? You seem to be missing the sqlite headers with the given macro definitions. When the python setup runs it compiles bindings to the sqlite native binary and copies a few .py files to the library. The _sqlite is typically a .pyd file (equivalent to a dll) which has calls to the sqlite library, in your case that did not get built.

Check the presence of the sqlite headers etc.

昔梦 2024-08-12 00:00:33

构建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

The correct way to build pysqlite is now on the website.

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

The build_static will download the latest sqlite code and statically compile against it. For a note I just did this on a 1and1 shared host.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文