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
181k26 gold badges184 silver badges279 bronze badges
asked Jun 15, 2011 at 11:34

2 Answers 2

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',)
answered Jun 15, 2011 at 11:59
Sign up to request clarification or add additional context in comments.

Comments

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

answered Jun 15, 2011 at 12:01

4 Comments

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?
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).
@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 groups.google.com/group/python-sqlite
did anyone figure out how to use it with Python3?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.