Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite version for Python 3.x

Tags:

python

sqlite

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

like image 279
Tarquin Avatar asked Dec 06 '22 21:12

Tarquin


1 Answers

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',)
like image 184
Ferdinand Beyer Avatar answered Dec 27 '22 23:12

Ferdinand Beyer