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

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
Tarquin
  • 41
  • 1
  • 1
  • 2

2 Answers2

12

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',)
Ferdinand Beyer
  • 64,979
  • 15
  • 154
  • 145
3

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 ...

Community
  • 1
  • 1
John Machin
  • 81,303
  • 11
  • 141
  • 189
  • Thanks for the reply. I realise my error for the version. Yes, I have tried to set enable_load_extentsion and I get an attribute error. Apparently this feature is disabled by default for some obscure reason. So my problem is solely how to set enable_load_extensions and it looks like I will have to compile pysqlite manually. The example in your link is for Unix. Can you hold my hand through the make/build process for windows? – Tarquin Jun 15 '11 at 12:41
  • FYI, it's not quite correct to say that Python x.x comes with sqlite3 library version y.y.y, since the sqlite3 library is not distributed with Python source. It's up to the builder or packager of a particular version of Python to choose which sqlite3 library to build or link with (or default to from the underlying operating system). – Ned Deily Jun 15 '11 at 18:45
  • @Tarquin: I have never built pysqlite from source, and I don't want to try. I'd strongly suggest upgrading your Python; `conn.enable_load_extension(True)` works straight out of the box with Windows Python 2.7.1 and 3.2.0. Otherwise I'd suggest asking on the pysqlite forum at http://groups.google.com/group/python-sqlite – John Machin Jun 15 '11 at 19:13
  • did anyone figure out how to use it with Python3? – Eliethesaiyan May 31 '16 at 08:08