Python 3.x 的 Sqlite 版本 [英] Sqlite version for Python 3.x

查看:25
本文介绍了Python 3.x 的 Sqlite 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Python 3.1.3 中使用 sqlite3,我需要将 enable_load_extension 设置为 true.为此,我相信我需要 sqlite 3.x 版.从这里的阅读帖子看来,合适的sqlite版本应该与python 2.6及更高版本捆绑在一起.但是,当我这样做时:

导入 sqlite3sqlite3.version_info

返回结果为:'2.4.1'

我在另一台运行 Python 2.6 的机器上得到了相同的答案.

pysqlite 站点没有 Python 3.x 的二进制文件.我的 Python 副本来自 Python 官方网站.

所以:1) 我应该在 3.1 中使用什么版本的 sqlite?2)如果我应该有一个更新的版本它去了哪里 - 我需要设置一个环境变量吗?2)如果我需要你

解决方案

不要将 SQLite 的版本与 pysqlite 的版本混淆,后者是 SQLite API 的 Python 绑定.您使用的 versionversion_info 属性指的是后者.

有没有想过为什么模块被命名为sqlite3?仅支持 3.x 版本!

要检查 SQLite 版本,请改用 sqlite_version:

导入 sqlite3打印 sqlite3.sqlite_version

在我的 Python 2.6 安装中,这会打印 3.5.9.对于 Python 3.2,我得到 3.7.4.

也可以使用SQL获取版本:

<预><代码>>>>导入 sqlite3>>>connection = sqlite3.connect(':memory:')>>>游标 = connection.cursor()>>>cursor.execute('SELECT sqlite_version()').fetchone()('3.7.4',)

I want to use sqlite3 with Python 3.1.3 and I need to set enable_load_extension to true. To do this I believe I need sqlite version 3.x. From reading posts here it looks like a suitable version of sqlite ought to be bundled with python version 2.6 and up. However, when I do:

import sqlite3
sqlite3.version_info

The result returned is: '2.4.1'

I get the same answer on a different machine running Python 2.6.

The pysqlite site has no binaries for Python 3.x. My copy of Python came from the official Python site.

So: 1) What version of sqlite should I have with 3.1? 2) If I ought to have a more up to date version where has it gone - do I need to set an environment variable? 2) If I need to u

解决方案

Don't confuse the version of SQLite with the version of pysqlite, the Python binding for the SQLite API. The version and version_info attributes you used refer to the latter.

Ever wondered why the module is named sqlite3? It only supports version 3.x!

To check the SQLite version, use sqlite_version instead:

import sqlite3
print sqlite3.sqlite_version

On my Python 2.6 installation, this prints 3.5.9. For Python 3.2, I get 3.7.4.

You can also use SQL to get the version:

>>> import sqlite3
>>> connection = sqlite3.connect(':memory:')
>>> cursor = connection.cursor()
>>> cursor.execute('SELECT sqlite_version()').fetchone()
('3.7.4',)

这篇关于Python 3.x 的 Sqlite 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆