Tarquin
Tarquin

Reputation: 41

Sqlite version for Python 3.x

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

Upvotes: 4

Views: 13102

Answers (2)

John Machin
John Machin

Reputation: 83032

You need sqlite3.sqlite_version_info ... this is 3.5.9 for Python 2.6 and 3.1, 3.6.21 for Python 2.7, and 3.7.4 for Python 3.2. What you have got is the version of pysqlite.

Have you tried to "set enable_load_extension to true"?

You may wish to read some of this long saga ...

Upvotes: 3

Ferdinand Beyer
Ferdinand Beyer

Reputation: 67247

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',)

Upvotes: 12

Related Questions